blob: 3d2566a2e0c4fbac921ce9d49411d090b6051ff7 [file] [log] [blame]
[email protected]a3536432013-03-26 08:14:311// 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
treib3be61a92017-04-25 13:03:388#include <memory>
treibd7182372017-04-28 11:39:119#include <string>
10#include <vector>
treib3be61a92017-04-25 13:03:3811
avib896c712015-12-26 02:10:4312#include "base/macros.h"
treib3be61a92017-04-25 13:03:3813#include "base/memory/weak_ptr.h"
treibd7182372017-04-28 11:39:1114#include "base/optional.h"
15#include "base/scoped_observer.h"
treib83e22f12017-05-10 15:12:0516#include "base/time/time.h"
Marc Treib9028a6a2017-12-06 16:21:5117#include "build/build_config.h"
treibd7182372017-04-28 11:39:1118#include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h"
[email protected]a3536432013-03-26 08:14:3119#include "content/public/browser/url_data_source.h"
20
Marc Treib9028a6a2017-12-06 16:21:5121#if defined(OS_ANDROID)
22#error "Instant is only used on desktop";
23#endif
24
treibd7182372017-04-28 11:39:1125struct OneGoogleBarData;
26class OneGoogleBarService;
[email protected]5df96ab2013-07-17 23:14:4827class Profile;
28
Chris Pickel3a227ae62017-08-24 10:47:2629namespace search_provider_logos {
30class LogoService;
31} // namespace search_provider_logos
32
[email protected]a3536432013-03-26 08:14:3133// Serves HTML and resources for the local new tab page i.e.
34// chrome-search://local-ntp/local-ntp.html
treibd7182372017-04-28 11:39:1135class LocalNtpSource : public content::URLDataSource,
36 public OneGoogleBarServiceObserver {
[email protected]a3536432013-03-26 08:14:3137 public:
[email protected]5df96ab2013-07-17 23:14:4838 explicit LocalNtpSource(Profile* profile);
[email protected]a3536432013-03-26 08:14:3139
40 private:
treib3be61a92017-04-25 13:03:3841 class GoogleSearchProviderTracker;
Chris Pickel3a227ae62017-08-24 10:47:2642 class DesktopLogoObserver;
treib3be61a92017-04-25 13:03:3843
treib83e22f12017-05-10 15:12:0544 struct OneGoogleBarRequest {
45 OneGoogleBarRequest(
46 base::TimeTicks start_time,
47 const content::URLDataSource::GotDataCallback& callback);
48 OneGoogleBarRequest(const OneGoogleBarRequest&);
49 ~OneGoogleBarRequest();
50
51 base::TimeTicks start_time;
52 content::URLDataSource::GotDataCallback callback;
53 };
54
Daniel Chenga542fca2014-10-21 09:51:2955 ~LocalNtpSource() override;
[email protected]a3536432013-03-26 08:14:3156
57 // Overridden from content::URLDataSource:
Daniel Chenga542fca2014-10-21 09:51:2958 std::string GetSource() const override;
59 void StartDataRequest(
[email protected]a3536432013-03-26 08:14:3160 const std::string& path,
jamedcd8b012016-09-20 02:03:5861 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
mostynbfb66cb4f2014-10-07 09:15:4262 const content::URLDataSource::GotDataCallback& callback) override;
Daniel Chenga542fca2014-10-21 09:51:2963 std::string GetMimeType(const std::string& path) const override;
toyoshim501ba312016-11-30 08:25:5564 bool AllowCaching() const override;
jamcf6f7622017-05-03 22:16:2865 bool ShouldServiceRequest(const GURL& url,
66 content::ResourceContext* resource_context,
67 int render_process_id) const override;
treib3be61a92017-04-25 13:03:3868 std::string GetContentSecurityPolicyScriptSrc() const override;
wychend6eb7792016-06-04 00:52:5369 std::string GetContentSecurityPolicyChildSrc() const override;
[email protected]a3536432013-03-26 08:14:3170
treibd7182372017-04-28 11:39:1171 // Overridden from OneGoogleBarServiceObserver:
Marc Treibc3b58c82017-08-01 12:56:5872 void OnOneGoogleBarDataUpdated() override;
treibd7182372017-04-28 11:39:1173 void OnOneGoogleBarServiceShuttingDown() override;
74
treib83e22f12017-05-10 15:12:0575 void ServeOneGoogleBar(const base::Optional<OneGoogleBarData>& data);
treibd7182372017-04-28 11:39:1176
treib3be61a92017-04-25 13:03:3877 void DefaultSearchProviderIsGoogleChanged(bool is_google);
78
79 void SetDefaultSearchProviderIsGoogleOnIOThread(bool is_google);
80
Ondrej Skopek4fbead82017-08-17 13:11:3281 void GoogleBaseUrlChanged(const GURL& google_base_url);
82
83 void SetGoogleBaseUrlOnIOThread(const GURL& google_base_url);
84
treibd7182372017-04-28 11:39:1185 Profile* const profile_;
86
87 OneGoogleBarService* one_google_bar_service_;
88
89 ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver>
90 one_google_bar_service_observer_;
91
Chris Pickel3a227ae62017-08-24 10:47:2692 search_provider_logos::LogoService* logo_service_;
93 std::unique_ptr<DesktopLogoObserver> logo_observer_;
94
treib83e22f12017-05-10 15:12:0595 std::vector<OneGoogleBarRequest> one_google_bar_requests_;
[email protected]5df96ab2013-07-17 23:14:4896
treib3be61a92017-04-25 13:03:3897 std::unique_ptr<GoogleSearchProviderTracker> google_tracker_;
98 bool default_search_provider_is_google_;
99 // A copy of |default_search_provider_is_google_| for use on the IO thread.
100 bool default_search_provider_is_google_io_thread_;
101
Ondrej Skopek4fbead82017-08-17 13:11:32102 GURL google_base_url_;
103 // A copy of |google_base_url_| for use on the IO thread.
104 GURL google_base_url_io_thread_;
105
treib3be61a92017-04-25 13:03:38106 base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_;
107
[email protected]a3536432013-03-26 08:14:31108 DISALLOW_COPY_AND_ASSIGN(LocalNtpSource);
109};
110
111#endif // CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_