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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 2888553002: Instant: small cleanups (Closed)
Patch Set: . Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_tab.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search/instant_service.h" 13 #include "chrome/browser/search/instant_service.h"
15 #include "chrome/browser/search/instant_service_factory.h" 14 #include "chrome/browser/search/instant_service_factory.h"
16 #include "chrome/browser/ui/browser_instant_controller.h" 15 #include "chrome/browser/ui/browser_instant_controller.h"
17 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
18 #include "url/gurl.h" 17 #include "url/gurl.h"
19 18
20 namespace { 19 namespace {
21 20
22 bool IsContentsFrom(const InstantTab* page, 21 bool IsContentsFrom(const InstantTab* page,
23 const content::WebContents* contents) { 22 const content::WebContents* contents) {
24 return page && (page->web_contents() == contents); 23 return page && (page->web_contents() == contents);
25 } 24 }
26 25
27 } // namespace 26 } // namespace
28 27
29 InstantController::InstantController(BrowserInstantController* browser) 28 InstantController::InstantController(BrowserInstantController* browser)
30 : browser_(browser) { 29 : browser_(browser) {}
31 }
32 30
33 InstantController::~InstantController() { 31 InstantController::~InstantController() = default;
34 }
35 32
36 void InstantController::SearchModeChanged(const SearchMode& old_mode, 33 void InstantController::SearchModeChanged(const SearchMode& old_mode,
37 const SearchMode& new_mode) { 34 const SearchMode& new_mode) {
38 LogDebugEvent(base::StringPrintf( 35 LogDebugEvent(base::StringPrintf(
39 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, 36 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin,
40 old_mode.mode, new_mode.origin, new_mode.mode)); 37 old_mode.mode, new_mode.origin, new_mode.mode));
41 38
42 search_mode_ = new_mode; 39 search_mode_ = new_mode;
43 ResetInstantTab(); 40 ResetInstantTab();
44 } 41 }
(...skipping 15 matching lines...) Expand all
60 57
61 void InstantController::ClearDebugEvents() { 58 void InstantController::ClearDebugEvents() {
62 debug_events_.clear(); 59 debug_events_.clear();
63 } 60 }
64 61
65 void InstantController::InstantTabAboutToNavigateMainFrame( 62 void InstantController::InstantTabAboutToNavigateMainFrame(
66 const content::WebContents* contents, 63 const content::WebContents* contents,
67 const GURL& url) { 64 const GURL& url) {
68 DCHECK(IsContentsFrom(instant_tab_.get(), contents)); 65 DCHECK(IsContentsFrom(instant_tab_.get(), contents));
69 66
70 // The Instant tab navigated. Send it the data it needs to display 67 // The Instant tab navigated (which means it had instant support both before
71 // properly. 68 // and after the navigation). This may cause it to be assigned to a new
72 // TODO(treib): Doesn't seem to be necessary. crbug.com/627747 69 // renderer process, which doesn't have the most visited/theme data yet, so
70 // send it now.
71 // TODO(treib): This seems unnecessarily convoluted and fragile. Can't we just
72 // send this when the Instant process is created?
73 UpdateInfoForInstantTab(); 73 UpdateInfoForInstantTab();
74 } 74 }
75 75
76 void InstantController::ResetInstantTab() { 76 void InstantController::ResetInstantTab() {
77 if (search_mode_.is_origin_ntp()) { 77 if (search_mode_.is_origin_ntp()) {
78 content::WebContents* active_tab = browser_->GetActiveWebContents(); 78 content::WebContents* active_tab = browser_->GetActiveWebContents();
79 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { 79 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) {
80 instant_tab_.reset(new InstantTab(this, active_tab)); 80 instant_tab_.reset(new InstantTab(this, active_tab));
81 instant_tab_->Init(); 81 instant_tab_->Init();
82 UpdateInfoForInstantTab(); 82 UpdateInfoForInstantTab();
83 } 83 }
84 } else { 84 } else {
85 instant_tab_.reset(); 85 instant_tab_.reset();
86 } 86 }
87 } 87 }
88 88
89 void InstantController::UpdateInfoForInstantTab() { 89 void InstantController::UpdateInfoForInstantTab() {
90 DCHECK(instant_tab_); 90 DCHECK(instant_tab_);
91 InstantService* instant_service = GetInstantService(); 91 InstantService* instant_service = GetInstantService();
92 if (instant_service) { 92 if (instant_service) {
93 instant_service->UpdateThemeInfo(); 93 instant_service->UpdateThemeInfo();
94 instant_service->UpdateMostVisitedItemsInfo(); 94 instant_service->UpdateMostVisitedItemsInfo();
95 } 95 }
96 } 96 }
97 97
98 InstantService* InstantController::GetInstantService() const { 98 InstantService* InstantController::GetInstantService() const {
99 return InstantServiceFactory::GetForProfile(browser_->profile()); 99 return InstantServiceFactory::GetForProfile(browser_->profile());
100 } 100 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698