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

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_api.cc

Issue 171813010: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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) 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 // Implements the Chrome Extensions Cookies API. 5 // Implements the Chrome Extensions Cookies API.
6 6
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace Get = extensions::api::cookies::Get; 42 namespace Get = extensions::api::cookies::Get;
43 namespace GetAll = extensions::api::cookies::GetAll; 43 namespace GetAll = extensions::api::cookies::GetAll;
44 namespace GetAllCookieStores = extensions::api::cookies::GetAllCookieStores; 44 namespace GetAllCookieStores = extensions::api::cookies::GetAllCookieStores;
45 namespace Remove = extensions::api::cookies::Remove; 45 namespace Remove = extensions::api::cookies::Remove;
46 namespace Set = extensions::api::cookies::Set; 46 namespace Set = extensions::api::cookies::Set;
47 47
48 namespace extensions { 48 namespace extensions {
49 namespace cookies = api::cookies; 49 namespace cookies = api::cookies;
50 namespace keys = cookies_api_constants; 50 namespace keys = cookies_api_constants;
51 51
52 CookiesEventRouter::CookiesEventRouter(Profile* profile) 52 CookiesEventRouter::CookiesEventRouter(content::BrowserContext* context)
53 : profile_(profile) { 53 : profile_(Profile::FromBrowserContext(context)) {
54 CHECK(registrar_.IsEmpty()); 54 CHECK(registrar_.IsEmpty());
55 registrar_.Add(this, 55 registrar_.Add(this,
56 chrome::NOTIFICATION_COOKIE_CHANGED, 56 chrome::NOTIFICATION_COOKIE_CHANGED,
57 content::NotificationService::AllBrowserContextsAndSources()); 57 content::NotificationService::AllBrowserContextsAndSources());
58 } 58 }
59 59
60 CookiesEventRouter::~CookiesEventRouter() { 60 CookiesEventRouter::~CookiesEventRouter() {
61 } 61 }
62 62
63 void CookiesEventRouter::Observe( 63 void CookiesEventRouter::Observe(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 args->Append(dict); 123 args->Append(dict);
124 124
125 GURL cookie_domain = 125 GURL cookie_domain =
126 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); 126 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie);
127 DispatchEvent(profile, 127 DispatchEvent(profile,
128 cookies::OnChanged::kEventName, 128 cookies::OnChanged::kEventName,
129 args.Pass(), 129 args.Pass(),
130 cookie_domain); 130 cookie_domain);
131 } 131 }
132 132
133 void CookiesEventRouter::DispatchEvent( 133 void CookiesEventRouter::DispatchEvent(content::BrowserContext* context,
134 Profile* profile, 134 const std::string& event_name,
135 const std::string& event_name, 135 scoped_ptr<base::ListValue> event_args,
136 scoped_ptr<base::ListValue> event_args, 136 GURL& cookie_domain) {
137 GURL& cookie_domain) { 137 EventRouter* router =
138 EventRouter* router = profile ? 138 context ? extensions::ExtensionSystem::Get(context)->event_router()
139 extensions::ExtensionSystem::Get(profile)->event_router() : NULL; 139 : NULL;
140 if (!router) 140 if (!router)
141 return; 141 return;
142 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); 142 scoped_ptr<Event> event(new Event(event_name, event_args.Pass()));
143 event->restrict_to_browser_context = profile; 143 event->restrict_to_browser_context = context;
144 event->event_url = cookie_domain; 144 event->event_url = cookie_domain;
145 router->BroadcastEvent(event.Pass()); 145 router->BroadcastEvent(event.Pass());
146 } 146 }
147 147
148 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, 148 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url,
149 bool check_host_permissions) { 149 bool check_host_permissions) {
150 *url = GURL(url_string); 150 *url = GURL(url_string);
151 if (!url->is_valid()) { 151 if (!url->is_valid()) {
152 error_ = ErrorUtils::FormatErrorMessage( 152 error_ = ErrorUtils::FormatErrorMessage(
153 keys::kInvalidUrlError, url_string); 153 keys::kInvalidUrlError, url_string);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 return g_factory.Pointer(); 579 return g_factory.Pointer();
580 } 580 }
581 581
582 void CookiesAPI::OnListenerAdded( 582 void CookiesAPI::OnListenerAdded(
583 const extensions::EventListenerInfo& details) { 583 const extensions::EventListenerInfo& details) {
584 cookies_event_router_.reset(new CookiesEventRouter(profile_)); 584 cookies_event_router_.reset(new CookiesEventRouter(profile_));
585 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 585 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
586 } 586 }
587 587
588 } // namespace extensions 588 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698