| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/bookmarks/bookmark_prompt_controller.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // static | 156 // static |
| 157 void BookmarkPromptController::DisableBookmarkPrompt( | 157 void BookmarkPromptController::DisableBookmarkPrompt( |
| 158 PrefServiceBase* prefs) { | 158 PrefServiceBase* prefs) { |
| 159 UMA_HISTOGRAM_ENUMERATION("BookmarkPrompt.DisabledReason", | 159 UMA_HISTOGRAM_ENUMERATION("BookmarkPrompt.DisabledReason", |
| 160 PROMPT_DISABLED_REASON_BY_MANUAL, | 160 PROMPT_DISABLED_REASON_BY_MANUAL, |
| 161 PROMPT_DISABLED_REASON_LIMIT); | 161 PROMPT_DISABLED_REASON_LIMIT); |
| 162 BookmarkPromptPrefs prompt_prefs(prefs); | 162 BookmarkPromptPrefs prompt_prefs(prefs); |
| 163 prompt_prefs.DisableBookmarkPrompt(); | 163 prompt_prefs.DisableBookmarkPrompt(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void BookmarkPromptController::ActiveTabChanged(TabContents*, | 166 void BookmarkPromptController::ActiveTabChanged(WebContents* old_contents, |
| 167 TabContents* new_contents, | 167 WebContents* new_contents, |
| 168 int, bool) { | 168 int index, |
| 169 bool user_gesture) { |
| 169 SetWebContents(new_contents); | 170 SetWebContents(new_contents); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void BookmarkPromptController::AddedBookmarkInternal(Browser* browser, | 173 void BookmarkPromptController::AddedBookmarkInternal(Browser* browser, |
| 173 const GURL& url) { | 174 const GURL& url) { |
| 174 if (browser == browser_ && url == last_prompted_url_) { | 175 if (browser == browser_ && url == last_prompted_url_) { |
| 175 last_prompted_url_ = GURL::EmptyGURL(); | 176 last_prompted_url_ = GURL::EmptyGURL(); |
| 176 UMA_HISTOGRAM_TIMES("BookmarkPrompt.AddedBookmark", | 177 UMA_HISTOGRAM_TIMES("BookmarkPrompt.AddedBookmark", |
| 177 base::Time::Now() - last_prompted_time_); | 178 base::Time::Now() - last_prompted_time_); |
| 178 } | 179 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 270 } |
| 270 | 271 |
| 271 void BookmarkPromptController::SetBrowser(Browser* browser) { | 272 void BookmarkPromptController::SetBrowser(Browser* browser) { |
| 272 if (browser_ == browser) | 273 if (browser_ == browser) |
| 273 return; | 274 return; |
| 274 if (browser_) | 275 if (browser_) |
| 275 browser_->tab_strip_model()->RemoveObserver(this); | 276 browser_->tab_strip_model()->RemoveObserver(this); |
| 276 browser_ = browser; | 277 browser_ = browser; |
| 277 if (browser_) | 278 if (browser_) |
| 278 browser_->tab_strip_model()->AddObserver(this); | 279 browser_->tab_strip_model()->AddObserver(this); |
| 279 SetWebContents(browser_ ? chrome::GetActiveTabContents(browser_) : NULL); | 280 SetWebContents(browser_ ? chrome::GetActiveWebContents(browser_) : NULL); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void BookmarkPromptController::SetWebContents(TabContents* tab_contents) { | 283 void BookmarkPromptController::SetWebContents(WebContents* web_contents) { |
| 283 WebContents* web_contents = | |
| 284 tab_contents ? tab_contents->web_contents() : NULL; | |
| 285 if (web_contents_) { | 284 if (web_contents_) { |
| 286 last_prompted_url_ = GURL::EmptyGURL(); | 285 last_prompted_url_ = GURL::EmptyGURL(); |
| 287 query_url_consumer_.CancelAllRequests(); | 286 query_url_consumer_.CancelAllRequests(); |
| 288 registrar_.Remove( | 287 registrar_.Remove( |
| 289 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 288 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 290 content::Source<WebContents>(web_contents_)); | 289 content::Source<WebContents>(web_contents_)); |
| 291 } | 290 } |
| 292 web_contents_ = web_contents; | 291 web_contents_ = web_contents; |
| 293 if (web_contents_) { | 292 if (web_contents_) { |
| 294 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 293 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 295 content::Source<WebContents>(web_contents_)); | 294 content::Source<WebContents>(web_contents_)); |
| 296 } | 295 } |
| 297 } | 296 } |
| OLD | NEW |