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

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_tab_helper.cc

Issue 7013001: Rename BookmarksTabHelper to BookmarkTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bookmarks_tab_helper.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
6 6
7 #include "chrome/browser/bookmarks/bookmark_model.h" 7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/bookmarks/bookmarks_tab_helper_delegate.h" 9 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "content/common/notification_service.h" 11 #include "content/common/notification_service.h"
12 12
13 BookmarksTabHelper::BookmarksTabHelper(TabContentsWrapper* tab_contents) 13 BookmarkTabHelper::BookmarkTabHelper(TabContentsWrapper* tab_contents)
14 : TabContentsObserver(tab_contents->tab_contents()), 14 : TabContentsObserver(tab_contents->tab_contents()),
15 is_starred_(false), 15 is_starred_(false),
16 tab_contents_wrapper_(tab_contents), 16 tab_contents_wrapper_(tab_contents),
17 delegate_(NULL) { 17 delegate_(NULL) {
18 // Register for notifications about URL starredness changing on any profile. 18 // Register for notifications about URL starredness changing on any profile.
19 registrar_.Add(this, NotificationType::URLS_STARRED, 19 registrar_.Add(this, NotificationType::URLS_STARRED,
20 NotificationService::AllSources()); 20 NotificationService::AllSources());
21 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, 21 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
22 NotificationService::AllSources()); 22 NotificationService::AllSources());
23 } 23 }
24 24
25 BookmarksTabHelper::~BookmarksTabHelper() { 25 BookmarkTabHelper::~BookmarkTabHelper() {
26 // We don't want any notifications while we're running our destructor. 26 // We don't want any notifications while we're running our destructor.
27 registrar_.RemoveAll(); 27 registrar_.RemoveAll();
28 } 28 }
29 29
30 void BookmarksTabHelper::DidNavigateMainFramePostCommit( 30 void BookmarkTabHelper::DidNavigateMainFramePostCommit(
31 const NavigationController::LoadCommittedDetails& /*details*/, 31 const NavigationController::LoadCommittedDetails& /*details*/,
32 const ViewHostMsg_FrameNavigate_Params& /*params*/) { 32 const ViewHostMsg_FrameNavigate_Params& /*params*/) {
33 UpdateStarredStateForCurrentURL(); 33 UpdateStarredStateForCurrentURL();
34 } 34 }
35 35
36 void BookmarksTabHelper::Observe(NotificationType type, 36 void BookmarkTabHelper::Observe(NotificationType type,
37 const NotificationSource& source, 37 const NotificationSource& source,
38 const NotificationDetails& details) { 38 const NotificationDetails& details) {
39 switch (type.value) { 39 switch (type.value) {
40 case NotificationType::BOOKMARK_MODEL_LOADED: 40 case NotificationType::BOOKMARK_MODEL_LOADED:
41 // BookmarkModel finished loading, fall through to update starred state. 41 // BookmarkModel finished loading, fall through to update starred state.
42 case NotificationType::URLS_STARRED: { 42 case NotificationType::URLS_STARRED: {
43 // Somewhere, a URL has been starred. 43 // Somewhere, a URL has been starred.
44 // Ignore notifications for profiles other than our current one. 44 // Ignore notifications for profiles other than our current one.
45 Profile* source_profile = Source<Profile>(source).ptr(); 45 Profile* source_profile = Source<Profile>(source).ptr();
46 if (!source_profile || 46 if (!source_profile ||
47 !source_profile->IsSameProfile(tab_contents_wrapper_->profile())) 47 !source_profile->IsSameProfile(tab_contents_wrapper_->profile()))
48 return; 48 return;
49 49
50 UpdateStarredStateForCurrentURL(); 50 UpdateStarredStateForCurrentURL();
51 break; 51 break;
52 } 52 }
53 53
54 default: 54 default:
55 NOTREACHED(); 55 NOTREACHED();
56 } 56 }
57 } 57 }
58 58
59 void BookmarksTabHelper::UpdateStarredStateForCurrentURL() { 59 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() {
60 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel(); 60 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel();
61 const bool old_state = is_starred_; 61 const bool old_state = is_starred_;
62 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL())); 62 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL()));
63 63
64 if (is_starred_ != old_state && delegate()) 64 if (is_starred_ != old_state && delegate())
65 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_); 65 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_);
66 } 66 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/bookmarks/bookmark_tab_helper.h ('k') | chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698