blob: 3da0d45169827ea415402175f0f8ba853aee2651 [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
Marc Treib15d80202017-12-08 16:38:4733// Serves HTML and resources for the local New Tab page, i.e.
34// chrome-search://local-ntp/local-ntp.html.
35// WARNING: Due to the threading model of URLDataSource, some methods of this
36// class are called on the UI thread, others on the IO thread. All data members
37// live on the UI thread, so make sure not to access them from the IO thread!
38// To prevent accidental access, all methods that get called on the IO thread
39// are implemented as non-member functions.
treibd7182372017-04-28 11:39:1140class LocalNtpSource : public content::URLDataSource,
41 public OneGoogleBarServiceObserver {
[email protected]a3536432013-03-26 08:14:3142 public:
[email protected]5df96ab2013-07-17 23:14:4843 explicit LocalNtpSource(Profile* profile);
[email protected]a3536432013-03-26 08:14:3144
45 private:
treib3be61a92017-04-25 13:03:3846 class GoogleSearchProviderTracker;
Chris Pickel3a227ae62017-08-24 10:47:2647 class DesktopLogoObserver;
treib3be61a92017-04-25 13:03:3848
treib83e22f12017-05-10 15:12:0549 struct OneGoogleBarRequest {
50 OneGoogleBarRequest(
51 base::TimeTicks start_time,
52 const content::URLDataSource::GotDataCallback& callback);
53 OneGoogleBarRequest(const OneGoogleBarRequest&);
54 ~OneGoogleBarRequest();
55
56 base::TimeTicks start_time;
57 content::URLDataSource::GotDataCallback callback;
58 };
59
Daniel Chenga542fca2014-10-21 09:51:2960 ~LocalNtpSource() override;
[email protected]a3536432013-03-26 08:14:3161
62 // Overridden from content::URLDataSource:
Daniel Chenga542fca2014-10-21 09:51:2963 std::string GetSource() const override;
64 void StartDataRequest(
[email protected]a3536432013-03-26 08:14:3165 const std::string& path,
jamedcd8b012016-09-20 02:03:5866 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
mostynbfb66cb4f2014-10-07 09:15:4267 const content::URLDataSource::GotDataCallback& callback) override;
Daniel Chenga542fca2014-10-21 09:51:2968 std::string GetMimeType(const std::string& path) const override;
toyoshim501ba312016-11-30 08:25:5569 bool AllowCaching() const override;
jamcf6f7622017-05-03 22:16:2870 bool ShouldServiceRequest(const GURL& url,
71 content::ResourceContext* resource_context,
72 int render_process_id) const override;
treib3be61a92017-04-25 13:03:3873 std::string GetContentSecurityPolicyScriptSrc() const override;
wychend6eb7792016-06-04 00:52:5374 std::string GetContentSecurityPolicyChildSrc() const override;
[email protected]a3536432013-03-26 08:14:3175
treibd7182372017-04-28 11:39:1176 // Overridden from OneGoogleBarServiceObserver:
Marc Treibc3b58c82017-08-01 12:56:5877 void OnOneGoogleBarDataUpdated() override;
treibd7182372017-04-28 11:39:1178 void OnOneGoogleBarServiceShuttingDown() override;
79
treib83e22f12017-05-10 15:12:0580 void ServeOneGoogleBar(const base::Optional<OneGoogleBarData>& data);
treibd7182372017-04-28 11:39:1181
treibd7182372017-04-28 11:39:1182 Profile* const profile_;
83
84 OneGoogleBarService* one_google_bar_service_;
85
86 ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver>
87 one_google_bar_service_observer_;
88
Chris Pickel3a227ae62017-08-24 10:47:2689 search_provider_logos::LogoService* logo_service_;
90 std::unique_ptr<DesktopLogoObserver> logo_observer_;
91
treib83e22f12017-05-10 15:12:0592 std::vector<OneGoogleBarRequest> one_google_bar_requests_;
[email protected]5df96ab2013-07-17 23:14:4893
treib3be61a92017-04-25 13:03:3894 std::unique_ptr<GoogleSearchProviderTracker> google_tracker_;
Ondrej Skopek4fbead82017-08-17 13:11:3295
treib3be61a92017-04-25 13:03:3896 base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_;
97
[email protected]a3536432013-03-26 08:14:3198 DISALLOW_COPY_AND_ASSIGN(LocalNtpSource);
99};
100
101#endif // CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_