[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ | ||||
6 | #define CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ | ||||
7 | |||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 8 | #include <memory> |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 9 | #include <string> |
10 | #include <vector> | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 11 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 12 | #include "base/macros.h" |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 14 | #include "base/optional.h" |
15 | #include "base/scoped_observer.h" | ||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame^] | 16 | #include "base/time/time.h" |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 17 | #include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h" |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 18 | #include "content/public/browser/url_data_source.h" |
19 | |||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 20 | struct OneGoogleBarData; |
21 | class OneGoogleBarService; | ||||
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 22 | class Profile; |
23 | |||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 24 | // Serves HTML and resources for the local new tab page i.e. |
25 | // chrome-search://local-ntp/local-ntp.html | ||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 26 | class LocalNtpSource : public content::URLDataSource, |
27 | public OneGoogleBarServiceObserver { | ||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 28 | public: |
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 29 | explicit LocalNtpSource(Profile* profile); |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 30 | |
31 | private: | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 32 | class GoogleSearchProviderTracker; |
33 | |||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame^] | 34 | struct OneGoogleBarRequest { |
35 | OneGoogleBarRequest( | ||||
36 | base::TimeTicks start_time, | ||||
37 | const content::URLDataSource::GotDataCallback& callback); | ||||
38 | OneGoogleBarRequest(const OneGoogleBarRequest&); | ||||
39 | ~OneGoogleBarRequest(); | ||||
40 | |||||
41 | base::TimeTicks start_time; | ||||
42 | content::URLDataSource::GotDataCallback callback; | ||||
43 | }; | ||||
44 | |||||
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 45 | ~LocalNtpSource() override; |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 46 | |
47 | // Overridden from content::URLDataSource: | ||||
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 48 | std::string GetSource() const override; |
49 | void StartDataRequest( | ||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 50 | const std::string& path, |
jam | edcd8b01 | 2016-09-20 02:03:58 | [diff] [blame] | 51 | const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
mostynb | fb66cb4f | 2014-10-07 09:15:42 | [diff] [blame] | 52 | const content::URLDataSource::GotDataCallback& callback) override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 53 | std::string GetMimeType(const std::string& path) const override; |
toyoshim | 501ba31 | 2016-11-30 08:25:55 | [diff] [blame] | 54 | bool AllowCaching() const override; |
jam | cf6f762 | 2017-05-03 22:16:28 | [diff] [blame] | 55 | bool ShouldServiceRequest(const GURL& url, |
56 | content::ResourceContext* resource_context, | ||||
57 | int render_process_id) const override; | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 58 | std::string GetContentSecurityPolicyScriptSrc() const override; |
wychen | d6eb779 | 2016-06-04 00:52:53 | [diff] [blame] | 59 | std::string GetContentSecurityPolicyChildSrc() const override; |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 60 | |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 61 | // Overridden from OneGoogleBarServiceObserver: |
62 | void OnOneGoogleBarDataChanged() override; | ||||
63 | void OnOneGoogleBarFetchFailed() override; | ||||
64 | void OnOneGoogleBarServiceShuttingDown() override; | ||||
65 | |||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame^] | 66 | void ServeOneGoogleBar(const base::Optional<OneGoogleBarData>& data); |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 67 | |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 68 | void DefaultSearchProviderIsGoogleChanged(bool is_google); |
69 | |||||
70 | void SetDefaultSearchProviderIsGoogleOnIOThread(bool is_google); | ||||
71 | |||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 72 | Profile* const profile_; |
73 | |||||
74 | OneGoogleBarService* one_google_bar_service_; | ||||
75 | |||||
76 | ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver> | ||||
77 | one_google_bar_service_observer_; | ||||
78 | |||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame^] | 79 | std::vector<OneGoogleBarRequest> one_google_bar_requests_; |
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 80 | |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 81 | std::unique_ptr<GoogleSearchProviderTracker> google_tracker_; |
82 | bool default_search_provider_is_google_; | ||||
83 | // A copy of |default_search_provider_is_google_| for use on the IO thread. | ||||
84 | bool default_search_provider_is_google_io_thread_; | ||||
85 | |||||
86 | base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_; | ||||
87 | |||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(LocalNtpSource); |
89 | }; | ||||
90 | |||||
91 | #endif // CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ |