Chromium Code Reviews| 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/extensions/api/history/history_api.h" | 5 #include "chrome/browser/extensions/api/history/history_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 DCHECK(false); | 125 DCHECK(false); |
| 126 } | 126 } |
| 127 | 127 |
| 128 visit_item->transition = transition; | 128 visit_item->transition = transition; |
| 129 | 129 |
| 130 return visit_item.Pass(); | 130 return visit_item.Pass(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace | 133 } // namespace |
| 134 | 134 |
| 135 HistoryEventRouter::HistoryEventRouter(Profile* profile) { | 135 HistoryEventRouter::HistoryEventRouter(Profile* profile, |
| 136 HistoryService* history_service) | |
| 137 : profile_(profile), history_service_(history_service) { | |
| 138 DCHECK(profile); | |
| 139 DCHECK(history_service); | |
| 136 const content::Source<Profile> source = content::Source<Profile>(profile); | 140 const content::Source<Profile> source = content::Source<Profile>(profile); |
| 137 registrar_.Add(this, | 141 registrar_.Add(this, |
| 138 chrome::NOTIFICATION_HISTORY_URL_VISITED, | |
| 139 source); | |
| 140 registrar_.Add(this, | |
| 141 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 142 chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 142 source); | 143 source); |
| 144 history_service_->AddObserver(this); | |
| 143 } | 145 } |
| 144 | 146 |
| 145 HistoryEventRouter::~HistoryEventRouter() {} | 147 HistoryEventRouter::~HistoryEventRouter() { |
| 148 history_service_->RemoveObserver(this); | |
| 149 } | |
| 146 | 150 |
| 147 void HistoryEventRouter::Observe(int type, | 151 void HistoryEventRouter::Observe(int type, |
| 148 const content::NotificationSource& source, | 152 const content::NotificationSource& source, |
| 149 const content::NotificationDetails& details) { | 153 const content::NotificationDetails& details) { |
| 150 switch (type) { | 154 switch (type) { |
| 151 case chrome::NOTIFICATION_HISTORY_URL_VISITED: | |
| 152 HistoryUrlVisited( | |
| 153 content::Source<Profile>(source).ptr(), | |
| 154 content::Details<const history::URLVisitedDetails>(details).ptr()); | |
| 155 break; | |
| 156 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | 155 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
| 157 HistoryUrlsRemoved( | 156 HistoryUrlsRemoved( |
| 158 content::Source<Profile>(source).ptr(), | 157 content::Source<Profile>(source).ptr(), |
| 159 content::Details<const history::URLsDeletedDetails>(details).ptr()); | 158 content::Details<const history::URLsDeletedDetails>(details).ptr()); |
| 160 break; | 159 break; |
| 161 default: | 160 default: |
| 162 NOTREACHED(); | 161 NOTREACHED(); |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 | 164 |
| 166 void HistoryEventRouter::HistoryUrlVisited( | 165 void HistoryEventRouter::OnURLVisited(HistoryService* history_service, |
| 167 Profile* profile, | 166 ui::PageTransition transition, |
| 168 const history::URLVisitedDetails* details) { | 167 const history::URLRow& row, |
| 169 scoped_ptr<HistoryItem> history_item = GetHistoryItem(details->row); | 168 const history::RedirectList& redirects, |
| 169 base::Time visit_time) { | |
| 170 DCHECK(history_service_ == history_service); | |
|
droger
2014/10/14 15:15:24
DHCEK_EQ
sdefresne
2014/10/14 16:02:05
Done.
| |
| 171 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); | |
| 170 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); | 172 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); |
| 171 | 173 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass()); |
| 172 DispatchEvent(profile, api::history::OnVisited::kEventName, args.Pass()); | |
| 173 } | 174 } |
| 174 | 175 |
| 175 void HistoryEventRouter::HistoryUrlsRemoved( | 176 void HistoryEventRouter::HistoryUrlsRemoved( |
| 176 Profile* profile, | 177 Profile* profile, |
| 177 const history::URLsDeletedDetails* details) { | 178 const history::URLsDeletedDetails* details) { |
| 178 OnVisitRemoved::Removed removed; | 179 OnVisitRemoved::Removed removed; |
| 179 removed.all_history = details->all_history; | 180 removed.all_history = details->all_history; |
| 180 | 181 |
| 181 std::vector<std::string>* urls = new std::vector<std::string>(); | 182 std::vector<std::string>* urls = new std::vector<std::string>(); |
| 182 for (history::URLRows::const_iterator iterator = details->rows.begin(); | 183 for (history::URLRows::const_iterator iterator = details->rows.begin(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { | 229 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { |
| 229 DependsOn(ActivityLog::GetFactoryInstance()); | 230 DependsOn(ActivityLog::GetFactoryInstance()); |
| 230 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 231 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { | 234 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 234 // TODO(vadimt): Remove ScopedProfile below once crbug.com/417106 is fixed. | 235 // TODO(vadimt): Remove ScopedProfile below once crbug.com/417106 is fixed. |
| 235 tracked_objects::ScopedProfile tracking_profile( | 236 tracked_objects::ScopedProfile tracking_profile( |
| 236 FROM_HERE_WITH_EXPLICIT_FUNCTION("HistoryAPI::OnListenerAdded")); | 237 FROM_HERE_WITH_EXPLICIT_FUNCTION("HistoryAPI::OnListenerAdded")); |
| 237 | 238 |
| 238 history_event_router_.reset( | 239 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 239 new HistoryEventRouter(Profile::FromBrowserContext(browser_context_))); | 240 history_event_router_.reset(new HistoryEventRouter( |
| 241 profile, | |
| 242 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS))); | |
| 240 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 243 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 241 } | 244 } |
| 242 | 245 |
| 243 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { | 246 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { |
| 244 GURL temp_url(url_string); | 247 GURL temp_url(url_string); |
| 245 if (!temp_url.is_valid()) { | 248 if (!temp_url.is_valid()) { |
| 246 error_ = kInvalidUrlError; | 249 error_ = kInvalidUrlError; |
| 247 return false; | 250 return false; |
| 248 } | 251 } |
| 249 url->Swap(&temp_url); | 252 url->Swap(&temp_url); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 } | 481 } |
| 479 | 482 |
| 480 return true; | 483 return true; |
| 481 } | 484 } |
| 482 | 485 |
| 483 void HistoryDeleteAllFunction::DeleteComplete() { | 486 void HistoryDeleteAllFunction::DeleteComplete() { |
| 484 SendAsyncResponse(); | 487 SendAsyncResponse(); |
| 485 } | 488 } |
| 486 | 489 |
| 487 } // namespace extensions | 490 } // namespace extensions |
| OLD | NEW |