Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/banners/app_banner_manager.cc

Issue 2969163002: Remove AppBannerManager::event_request_id(). (Closed)
Patch Set: Refactor into method Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/public/browser/navigation_handle.h" 23 #include "content/public/browser/navigation_handle.h"
24 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "mojo/public/cpp/bindings/interface_request.h" 26 #include "mojo/public/cpp/bindings/interface_request.h"
27 #include "services/service_manager/public/cpp/interface_provider.h" 27 #include "services/service_manager/public/cpp/interface_provider.h"
28 #include "third_party/WebKit/public/platform/modules/installation/installation.m ojom.h" 28 #include "third_party/WebKit/public/platform/modules/installation/installation.m ojom.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
30 30
31 namespace { 31 namespace {
32 32
33 int gCurrentRequestID = -1;
34 int gTimeDeltaInDaysForTesting = 0; 33 int gTimeDeltaInDaysForTesting = 0;
35 34
36 InstallableParams ParamsToGetManifest() { 35 InstallableParams ParamsToGetManifest() {
37 return InstallableParams(); 36 return InstallableParams();
38 } 37 }
39 38
40 } // anonymous namespace 39 } // anonymous namespace
41 40
42 namespace banners { 41 namespace banners {
43 42
(...skipping 14 matching lines...) Expand all
58 } 57 }
59 58
60 void AppBannerManager::RequestAppBanner(const GURL& validated_url, 59 void AppBannerManager::RequestAppBanner(const GURL& validated_url,
61 bool is_debug_mode) { 60 bool is_debug_mode) {
62 content::WebContents* contents = web_contents(); 61 content::WebContents* contents = web_contents();
63 62
64 // The only time we should start the pipeline while it is already running is 63 // The only time we should start the pipeline while it is already running is
65 // if it's been triggered from devtools. 64 // if it's been triggered from devtools.
66 if (is_active_or_pending()) { 65 if (is_active_or_pending()) {
67 DCHECK(is_debug_mode); 66 DCHECK(is_debug_mode);
68 weak_factory_.InvalidateWeakPtrs(); 67 ResetBindings();
69 } 68 }
70 69
71 UpdateState(State::ACTIVE); 70 UpdateState(State::ACTIVE);
72 triggered_by_devtools_ = is_debug_mode; 71 triggered_by_devtools_ = is_debug_mode;
73 page_requested_prompt_ = false; 72 page_requested_prompt_ = false;
74 73
75 // We only need to call ReportStatus if we aren't in debug mode (this avoids 74 // We only need to call ReportStatus if we aren't in debug mode (this avoids
76 // skew from testing). 75 // skew from testing).
77 DCHECK(!need_to_log_status_); 76 DCHECK(!need_to_log_status_);
78 need_to_log_status_ = !IsDebugMode(); 77 need_to_log_status_ = !IsDebugMode();
(...skipping 29 matching lines...) Expand all
108 } 107 }
109 108
110 void AppBannerManager::OnInstall() { 109 void AppBannerManager::OnInstall() {
111 blink::mojom::InstallationServicePtr installation_service; 110 blink::mojom::InstallationServicePtr installation_service;
112 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( 111 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface(
113 mojo::MakeRequest(&installation_service)); 112 mojo::MakeRequest(&installation_service));
114 DCHECK(installation_service); 113 DCHECK(installation_service);
115 installation_service->OnInstall(); 114 installation_service->OnInstall();
116 } 115 }
117 116
118 void AppBannerManager::SendBannerAccepted(int request_id) { 117 void AppBannerManager::SendBannerAccepted() {
119 if (request_id != gCurrentRequestID) 118 if (event_.is_bound())
120 return; 119 event_->BannerAccepted(GetBannerType());
121
122 DCHECK(event_.is_bound());
123 event_->BannerAccepted(GetBannerType());
124 } 120 }
125 121
126 void AppBannerManager::SendBannerDismissed(int request_id) { 122 void AppBannerManager::SendBannerDismissed() {
127 if (request_id != gCurrentRequestID) 123 if (event_.is_bound())
128 return; 124 event_->BannerDismissed();
129
130 DCHECK(event_.is_bound());
131 event_->BannerDismissed();
132 } 125 }
133 126
134 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() { 127 base::WeakPtr<AppBannerManager> AppBannerManager::GetWeakPtr() {
135 return weak_factory_.GetWeakPtr(); 128 return weak_factory_.GetWeakPtr();
136 } 129 }
137 130
138 AppBannerManager::AppBannerManager(content::WebContents* web_contents) 131 AppBannerManager::AppBannerManager(content::WebContents* web_contents)
139 : content::WebContentsObserver(web_contents), 132 : content::WebContentsObserver(web_contents),
140 SiteEngagementObserver(SiteEngagementService::Get( 133 SiteEngagementObserver(SiteEngagementService::Get(
141 Profile::FromBrowserContext(web_contents->GetBrowserContext()))), 134 Profile::FromBrowserContext(web_contents->GetBrowserContext()))),
142 state_(State::INACTIVE), 135 state_(State::INACTIVE),
143 manager_(InstallableManager::FromWebContents(web_contents)), 136 manager_(InstallableManager::FromWebContents(web_contents)),
144 event_request_id_(-1),
145 binding_(this), 137 binding_(this),
146 has_sufficient_engagement_(false), 138 has_sufficient_engagement_(false),
147 load_finished_(false), 139 load_finished_(false),
148 page_requested_prompt_(false), 140 page_requested_prompt_(false),
149 triggered_by_devtools_(false), 141 triggered_by_devtools_(false),
150 need_to_log_status_(false), 142 need_to_log_status_(false),
151 weak_factory_(this) { 143 weak_factory_(this) {
152 DCHECK(manager_); 144 DCHECK(manager_);
153 145
154 AppBannerSettingsHelper::UpdateFromFieldTrial(); 146 AppBannerSettingsHelper::UpdateFromFieldTrial();
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 325
334 if (code != NO_ERROR_DETECTED) 326 if (code != NO_ERROR_DETECTED)
335 ReportStatus(web_contents(), code); 327 ReportStatus(web_contents(), code);
336 328
337 // In every non-debug run through the banner pipeline, we should have called 329 // In every non-debug run through the banner pipeline, we should have called
338 // ReportStatus() and set need_to_log_status_ to false. The only case where 330 // ReportStatus() and set need_to_log_status_ to false. The only case where
339 // we don't is if we're still active and waiting for native app data, which is 331 // we don't is if we're still active and waiting for native app data, which is
340 // explicitly not logged. 332 // explicitly not logged.
341 DCHECK(!need_to_log_status_ || is_active()); 333 DCHECK(!need_to_log_status_ || is_active());
342 334
343 weak_factory_.InvalidateWeakPtrs(); 335 ResetBindings();
344 binding_.Close();
345 controller_.reset();
346 event_.reset();
347
348 UpdateState(State::COMPLETE); 336 UpdateState(State::COMPLETE);
349 need_to_log_status_ = false; 337 need_to_log_status_ = false;
350 has_sufficient_engagement_ = false; 338 has_sufficient_engagement_ = false;
351 } 339 }
352 340
353 void AppBannerManager::SendBannerPromptRequest() { 341 void AppBannerManager::SendBannerPromptRequest() {
354 RecordCouldShowBanner(); 342 RecordCouldShowBanner();
355
356 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); 343 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED);
357 event_request_id_ = ++gCurrentRequestID;
358 344
359 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( 345 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface(
360 mojo::MakeRequest(&controller_)); 346 mojo::MakeRequest(&controller_));
361 347
362 blink::mojom::AppBannerServicePtr banner_proxy; 348 blink::mojom::AppBannerServicePtr banner_proxy;
363 binding_.Bind(mojo::MakeRequest(&banner_proxy)); 349 binding_.Bind(mojo::MakeRequest(&banner_proxy));
364 controller_->BannerPromptRequest( 350 controller_->BannerPromptRequest(
365 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()}, 351 std::move(banner_proxy), mojo::MakeRequest(&event_), {GetBannerType()},
366 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); 352 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr()));
367 } 353 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 SendBannerPromptRequest(); 449 SendBannerPromptRequest();
464 } else if (load_finished_ && !is_active_or_pending()) { 450 } else if (load_finished_ && !is_active_or_pending()) {
465 // This performs some simple tests and starts async checks to test 451 // This performs some simple tests and starts async checks to test
466 // installability. It should be safe to start in response to user input. 452 // installability. It should be safe to start in response to user input.
467 // Don't call if we're already working on processing a banner request. 453 // Don't call if we're already working on processing a banner request.
468 RequestAppBanner(url, false /* is_debug_mode */); 454 RequestAppBanner(url, false /* is_debug_mode */);
469 } 455 }
470 } 456 }
471 } 457 }
472 458
459 void AppBannerManager::ResetBindings() {
460 weak_factory_.InvalidateWeakPtrs();
461 binding_.Close();
462 controller_.reset();
463 event_.reset();
464 }
465
473 void AppBannerManager::RecordCouldShowBanner() { 466 void AppBannerManager::RecordCouldShowBanner() {
474 content::WebContents* contents = web_contents(); 467 content::WebContents* contents = web_contents();
475 DCHECK(contents); 468 DCHECK(contents);
476 469
477 AppBannerSettingsHelper::RecordBannerEvent( 470 AppBannerSettingsHelper::RecordBannerEvent(
478 contents, validated_url_, GetAppIdentifier(), 471 contents, validated_url_, GetAppIdentifier(),
479 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); 472 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime());
480 } 473 }
481 474
482 bool AppBannerManager::CheckIfShouldShowBanner() { 475 bool AppBannerManager::CheckIfShouldShowBanner() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (is_pending_event()) { 564 if (is_pending_event()) {
572 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. 565 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner.
573 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); 566 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_);
574 } else { 567 } else {
575 // Log that the prompt request was made for when we get the prompt reply. 568 // Log that the prompt request was made for when we get the prompt reply.
576 page_requested_prompt_ = true; 569 page_requested_prompt_ = true;
577 } 570 }
578 } 571 }
579 572
580 } // namespace banners 573 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager.h ('k') | chrome/browser/banners/app_banner_manager_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698