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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/declarative_content_is_bookmarked_condition_tracker.cc

Issue 2216713002: Use BookmarkModelFactory::GetForBrowserContext everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bookmarks
Patch Set: Replace in .mm files Created 4 years, 4 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/extensions/api/declarative_content/declarative_content_ is_bookmarked_condition_tracker.h" 5 #include "chrome/browser/extensions/api/declarative_content/declarative_content_ is_bookmarked_condition_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" 13 #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "components/bookmarks/browser/bookmark_model.h" 14 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
17 #include "extensions/common/permissions/permissions_data.h" 16 #include "extensions/common/permissions/permissions_data.h"
18 17
19 namespace extensions { 18 namespace extensions {
20 19
21 namespace { 20 namespace {
22 21
23 const char kInvalidTypeOfParameter[] = "Attribute '%s' has an invalid type"; 22 const char kInvalidTypeOfParameter[] = "Attribute '%s' has an invalid type";
24 const char kIsBookmarkedRequiresBookmarkPermission[] = 23 const char kIsBookmarkedRequiresBookmarkPermission[] =
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 IsCurrentUrlBookmarked() != is_url_bookmarked_; 122 IsCurrentUrlBookmarked() != is_url_bookmarked_;
124 if (state_changed) 123 if (state_changed)
125 is_url_bookmarked_ = !is_url_bookmarked_; 124 is_url_bookmarked_ = !is_url_bookmarked_;
126 if (state_changed || request_evaluation_if_unchanged) 125 if (state_changed || request_evaluation_if_unchanged)
127 request_evaluation_.Run(web_contents()); 126 request_evaluation_.Run(web_contents());
128 } 127 }
129 128
130 bool DeclarativeContentIsBookmarkedConditionTracker::PerWebContentsTracker:: 129 bool DeclarativeContentIsBookmarkedConditionTracker::PerWebContentsTracker::
131 IsCurrentUrlBookmarked() { 130 IsCurrentUrlBookmarked() {
132 bookmarks::BookmarkModel* bookmark_model = 131 bookmarks::BookmarkModel* bookmark_model =
133 BookmarkModelFactory::GetForProfile( 132 BookmarkModelFactory::GetForBrowserContext(
134 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); 133 web_contents()->GetBrowserContext());
135 // BookmarkModel can be null during unit test execution. 134 // BookmarkModel can be null during unit test execution.
136 return bookmark_model && 135 return bookmark_model &&
137 bookmark_model->IsBookmarked(web_contents()->GetVisibleURL()); 136 bookmark_model->IsBookmarked(web_contents()->GetVisibleURL());
138 } 137 }
139 138
140 void DeclarativeContentIsBookmarkedConditionTracker::PerWebContentsTracker:: 139 void DeclarativeContentIsBookmarkedConditionTracker::PerWebContentsTracker::
141 WebContentsDestroyed() { 140 WebContentsDestroyed() {
142 web_contents_destroyed_.Run(web_contents()); 141 web_contents_destroyed_.Run(web_contents());
143 } 142 }
144 143
145 // 144 //
146 // DeclarativeContentIsBookmarkedConditionTracker 145 // DeclarativeContentIsBookmarkedConditionTracker
147 // 146 //
148 147
149 DeclarativeContentIsBookmarkedConditionTracker:: 148 DeclarativeContentIsBookmarkedConditionTracker::
150 DeclarativeContentIsBookmarkedConditionTracker(content::BrowserContext* context, 149 DeclarativeContentIsBookmarkedConditionTracker(content::BrowserContext* context,
151 Delegate* delegate) 150 Delegate* delegate)
152 : delegate_(delegate), 151 : delegate_(delegate),
153 extensive_bookmark_changes_in_progress_(0), 152 extensive_bookmark_changes_in_progress_(0),
154 scoped_bookmarks_observer_(this) { 153 scoped_bookmarks_observer_(this) {
155 bookmarks::BookmarkModel* bookmark_model = 154 bookmarks::BookmarkModel* bookmark_model =
156 BookmarkModelFactory::GetForProfile(Profile::FromBrowserContext(context)); 155 BookmarkModelFactory::GetForBrowserContext(context);
157 // Can be null during unit test execution. 156 // Can be null during unit test execution.
158 if (bookmark_model) 157 if (bookmark_model)
159 scoped_bookmarks_observer_.Add(bookmark_model); 158 scoped_bookmarks_observer_.Add(bookmark_model);
160 } 159 }
161 160
162 DeclarativeContentIsBookmarkedConditionTracker:: 161 DeclarativeContentIsBookmarkedConditionTracker::
163 ~DeclarativeContentIsBookmarkedConditionTracker() { 162 ~DeclarativeContentIsBookmarkedConditionTracker() {
164 } 163 }
165 164
166 std::string DeclarativeContentIsBookmarkedConditionTracker:: 165 std::string DeclarativeContentIsBookmarkedConditionTracker::
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 per_web_contents_tracker_.erase(contents); 278 per_web_contents_tracker_.erase(contents);
280 } 279 }
281 280
282 void DeclarativeContentIsBookmarkedConditionTracker:: 281 void DeclarativeContentIsBookmarkedConditionTracker::
283 UpdateAllPerWebContentsTrackers() { 282 UpdateAllPerWebContentsTrackers() {
284 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) 283 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_)
285 web_contents_tracker_pair.second->UpdateState(false); 284 web_contents_tracker_pair.second->UpdateState(false);
286 } 285 }
287 286
288 } // namespace extensions 287 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698