blob: 0187d5f2e02f572ba3ad550a0583d8ccae900753 [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"
treibd7182372017-04-28 11:39:1117#include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h"
[email protected]a3536432013-03-26 08:14:3118#include "content/public/browser/url_data_source.h"
19
treibd7182372017-04-28 11:39:1120struct OneGoogleBarData;
21class OneGoogleBarService;
[email protected]5df96ab2013-07-17 23:14:4822class Profile;
23
[email protected]a3536432013-03-26 08:14:3124// Serves HTML and resources for the local new tab page i.e.
25// chrome-search://local-ntp/local-ntp.html
treibd7182372017-04-28 11:39:1126class LocalNtpSource : public content::URLDataSource,
27 public OneGoogleBarServiceObserver {
[email protected]a3536432013-03-26 08:14:3128 public:
[email protected]5df96ab2013-07-17 23:14:4829 explicit LocalNtpSource(Profile* profile);
[email protected]a3536432013-03-26 08:14:3130
31 private:
treib3be61a92017-04-25 13:03:3832 class GoogleSearchProviderTracker;
33
treib83e22f12017-05-10 15:12:0534 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 Chenga542fca2014-10-21 09:51:2945 ~LocalNtpSource() override;
[email protected]a3536432013-03-26 08:14:3146
47 // Overridden from content::URLDataSource:
Daniel Chenga542fca2014-10-21 09:51:2948 std::string GetSource() const override;
49 void StartDataRequest(
[email protected]a3536432013-03-26 08:14:3150 const std::string& path,
jamedcd8b012016-09-20 02:03:5851 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
mostynbfb66cb4f2014-10-07 09:15:4252 const content::URLDataSource::GotDataCallback& callback) override;
Daniel Chenga542fca2014-10-21 09:51:2953 std::string GetMimeType(const std::string& path) const override;
toyoshim501ba312016-11-30 08:25:5554 bool AllowCaching() const override;
jamcf6f7622017-05-03 22:16:2855 bool ShouldServiceRequest(const GURL& url,
56 content::ResourceContext* resource_context,
57 int render_process_id) const override;
treib3be61a92017-04-25 13:03:3858 std::string GetContentSecurityPolicyScriptSrc() const override;
wychend6eb7792016-06-04 00:52:5359 std::string GetContentSecurityPolicyChildSrc() const override;
[email protected]a3536432013-03-26 08:14:3160
treibd7182372017-04-28 11:39:1161 // Overridden from OneGoogleBarServiceObserver:
62 void OnOneGoogleBarDataChanged() override;
63 void OnOneGoogleBarFetchFailed() override;
64 void OnOneGoogleBarServiceShuttingDown() override;
65
treib83e22f12017-05-10 15:12:0566 void ServeOneGoogleBar(const base::Optional<OneGoogleBarData>& data);
treibd7182372017-04-28 11:39:1167
treib3be61a92017-04-25 13:03:3868 void DefaultSearchProviderIsGoogleChanged(bool is_google);
69
70 void SetDefaultSearchProviderIsGoogleOnIOThread(bool is_google);
71
treibd7182372017-04-28 11:39:1172 Profile* const profile_;
73
74 OneGoogleBarService* one_google_bar_service_;
75
76 ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver>
77 one_google_bar_service_observer_;
78
treib83e22f12017-05-10 15:12:0579 std::vector<OneGoogleBarRequest> one_google_bar_requests_;
[email protected]5df96ab2013-07-17 23:14:4880
treib3be61a92017-04-25 13:03:3881 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]a3536432013-03-26 08:14:3188 DISALLOW_COPY_AND_ASSIGN(LocalNtpSource);
89};
90
91#endif // CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_