OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/banners/app_banner_manager.h" | 5 #include "chrome/browser/banners/app_banner_manager.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | |
8 #include "base/strings/string_number_conversions.h" | |
7 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 9 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
8 #include "chrome/browser/banners/app_banner_debug_log.h" | 10 #include "chrome/browser/banners/app_banner_debug_log.h" |
9 #include "chrome/browser/banners/app_banner_settings_helper.h" | 11 #include "chrome/browser/banners/app_banner_settings_helper.h" |
10 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
11 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/frame_navigate_params.h" | 15 #include "content/public/common/frame_navigate_params.h" |
14 #include "content/public/common/origin_util.h" | 16 #include "content/public/common/origin_util.h" |
15 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
16 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
17 | 19 |
18 namespace { | 20 namespace { |
19 bool gDisableSecureCheckForTesting = false; | 21 bool gDisableSecureCheckForTesting = false; |
20 } // anonymous namespace | 22 } // anonymous namespace |
21 | 23 |
22 namespace banners { | 24 namespace banners { |
23 | 25 |
24 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, | 26 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, |
25 const GURL& second) { | 27 const GURL& second) { |
26 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 28 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
27 first.path() == second.path() && first.query() == second.query(); | 29 first.path() == second.path() && first.query() == second.query(); |
28 } | 30 } |
29 | 31 |
30 AppBannerManager::AppBannerManager(int icon_size) | 32 AppBannerManager::AppBannerManager(int icon_size) |
31 : ideal_icon_size_(icon_size), | 33 : ideal_icon_size_(icon_size), |
32 data_fetcher_(nullptr), | 34 data_fetcher_(nullptr), |
33 weak_factory_(this) { | 35 weak_factory_(this) { |
36 UpdateMinutesBetweenVisits(); | |
34 } | 37 } |
35 | 38 |
36 AppBannerManager::AppBannerManager(content::WebContents* web_contents, | 39 AppBannerManager::AppBannerManager(content::WebContents* web_contents, |
37 int icon_size) | 40 int icon_size) |
38 : content::WebContentsObserver(web_contents), | 41 : content::WebContentsObserver(web_contents), |
39 ideal_icon_size_(icon_size), | 42 ideal_icon_size_(icon_size), |
40 data_fetcher_(nullptr), | 43 data_fetcher_(nullptr), |
41 weak_factory_(this) { | 44 weak_factory_(this) { |
45 UpdateMinutesBetweenVisits(); | |
42 } | 46 } |
43 | 47 |
44 AppBannerManager::~AppBannerManager() { | 48 AppBannerManager::~AppBannerManager() { |
45 CancelActiveFetcher(); | 49 CancelActiveFetcher(); |
46 } | 50 } |
47 | 51 |
48 void AppBannerManager::DidCommitProvisionalLoadForFrame( | 52 void AppBannerManager::DidCommitProvisionalLoadForFrame( |
49 content::RenderFrameHost* render_frame_host, | 53 content::RenderFrameHost* render_frame_host, |
50 const GURL& url, | 54 const GURL& url, |
51 ui::PageTransition transition_type) { | 55 ui::PageTransition transition_type) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 if (data_fetcher_ != nullptr) { | 97 if (data_fetcher_ != nullptr) { |
94 data_fetcher_->Cancel(); | 98 data_fetcher_->Cancel(); |
95 data_fetcher_ = nullptr; | 99 data_fetcher_ = nullptr; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 bool AppBannerManager::IsFetcherActive() { | 103 bool AppBannerManager::IsFetcherActive() { |
100 return data_fetcher_ != nullptr && data_fetcher_->is_active(); | 104 return data_fetcher_ != nullptr && data_fetcher_->is_active(); |
101 } | 105 } |
102 | 106 |
107 void AppBannerManager::UpdateMinutesBetweenVisits() { | |
benwells
2015/08/24 06:55:52
Could you just move all this logic into AppBannerS
dominickn
2015/08/24 07:43:16
Done.
| |
108 std::string minutes_between_visits = | |
109 base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits"); | |
110 int minimum_minutes; | |
111 if (base::StringToInt(minutes_between_visits, &minimum_minutes)) | |
112 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes); | |
113 } | |
114 | |
103 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | 115 void AppBannerManager::DisableSecureSchemeCheckForTesting() { |
104 gDisableSecureCheckForTesting = true; | 116 gDisableSecureCheckForTesting = true; |
105 } | 117 } |
106 | 118 |
107 void AppBannerManager::ForceEngagementWeightsForTesting( | 119 void AppBannerManager::ForceEngagementWeightsForTesting( |
108 double direct_engagement, | 120 double direct_engagement, |
109 double indirect_engagement) { | 121 double indirect_engagement) { |
110 AppBannerSettingsHelper::SetEngagementWeights(direct_engagement, | 122 AppBannerSettingsHelper::SetEngagementWeights(direct_engagement, |
111 indirect_engagement); | 123 indirect_engagement); |
112 } | 124 } |
113 | 125 |
114 } // namespace banners | 126 } // namespace banners |
OLD | NEW |