| 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 const content::Source<Profile> source = content::Source<Profile>(profile); | 136 HistoryService* history_service) |
| 137 registrar_.Add(this, | 137 : profile_(profile), history_service_observer_(this) { |
| 138 chrome::NOTIFICATION_HISTORY_URL_VISITED, | 138 DCHECK(profile); |
| 139 source); | |
| 140 registrar_.Add(this, | 139 registrar_.Add(this, |
| 141 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 140 chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 142 source); | 141 content::Source<Profile>(profile)); |
| 142 history_service_observer_.Add(history_service); |
| 143 } | 143 } |
| 144 | 144 |
| 145 HistoryEventRouter::~HistoryEventRouter() {} | 145 HistoryEventRouter::~HistoryEventRouter() { |
| 146 } |
| 146 | 147 |
| 147 void HistoryEventRouter::Observe(int type, | 148 void HistoryEventRouter::Observe(int type, |
| 148 const content::NotificationSource& source, | 149 const content::NotificationSource& source, |
| 149 const content::NotificationDetails& details) { | 150 const content::NotificationDetails& details) { |
| 150 switch (type) { | 151 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED); |
| 151 case chrome::NOTIFICATION_HISTORY_URL_VISITED: | 152 HistoryUrlsRemoved( |
| 152 HistoryUrlVisited( | 153 content::Source<Profile>(source).ptr(), |
| 153 content::Source<Profile>(source).ptr(), | 154 content::Details<const history::URLsDeletedDetails>(details).ptr()); |
| 154 content::Details<const history::URLVisitedDetails>(details).ptr()); | |
| 155 break; | |
| 156 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | |
| 157 HistoryUrlsRemoved( | |
| 158 content::Source<Profile>(source).ptr(), | |
| 159 content::Details<const history::URLsDeletedDetails>(details).ptr()); | |
| 160 break; | |
| 161 default: | |
| 162 NOTREACHED(); | |
| 163 } | |
| 164 } | 155 } |
| 165 | 156 |
| 166 void HistoryEventRouter::HistoryUrlVisited( | 157 void HistoryEventRouter::OnURLVisited(HistoryService* history_service, |
| 167 Profile* profile, | 158 ui::PageTransition transition, |
| 168 const history::URLVisitedDetails* details) { | 159 const history::URLRow& row, |
| 169 scoped_ptr<HistoryItem> history_item = GetHistoryItem(details->row); | 160 const history::RedirectList& redirects, |
| 161 base::Time visit_time) { |
| 162 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); |
| 170 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); | 163 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); |
| 171 | 164 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass()); |
| 172 DispatchEvent(profile, api::history::OnVisited::kEventName, args.Pass()); | |
| 173 } | 165 } |
| 174 | 166 |
| 175 void HistoryEventRouter::HistoryUrlsRemoved( | 167 void HistoryEventRouter::HistoryUrlsRemoved( |
| 176 Profile* profile, | 168 Profile* profile, |
| 177 const history::URLsDeletedDetails* details) { | 169 const history::URLsDeletedDetails* details) { |
| 178 OnVisitRemoved::Removed removed; | 170 OnVisitRemoved::Removed removed; |
| 179 removed.all_history = details->all_history; | 171 removed.all_history = details->all_history; |
| 180 | 172 |
| 181 std::vector<std::string>* urls = new std::vector<std::string>(); | 173 std::vector<std::string>* urls = new std::vector<std::string>(); |
| 182 for (history::URLRows::const_iterator iterator = details->rows.begin(); | 174 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() { | 220 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { |
| 229 DependsOn(ActivityLog::GetFactoryInstance()); | 221 DependsOn(ActivityLog::GetFactoryInstance()); |
| 230 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 222 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 231 } | 223 } |
| 232 | 224 |
| 233 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { | 225 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 234 // TODO(vadimt): Remove ScopedProfile below once crbug.com/417106 is fixed. | 226 // TODO(vadimt): Remove ScopedProfile below once crbug.com/417106 is fixed. |
| 235 tracked_objects::ScopedProfile tracking_profile( | 227 tracked_objects::ScopedProfile tracking_profile( |
| 236 FROM_HERE_WITH_EXPLICIT_FUNCTION("HistoryAPI::OnListenerAdded")); | 228 FROM_HERE_WITH_EXPLICIT_FUNCTION("HistoryAPI::OnListenerAdded")); |
| 237 | 229 |
| 238 history_event_router_.reset( | 230 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 239 new HistoryEventRouter(Profile::FromBrowserContext(browser_context_))); | 231 history_event_router_.reset(new HistoryEventRouter( |
| 232 profile, |
| 233 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS))); |
| 240 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 234 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 241 } | 235 } |
| 242 | 236 |
| 243 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { | 237 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { |
| 244 GURL temp_url(url_string); | 238 GURL temp_url(url_string); |
| 245 if (!temp_url.is_valid()) { | 239 if (!temp_url.is_valid()) { |
| 246 error_ = kInvalidUrlError; | 240 error_ = kInvalidUrlError; |
| 247 return false; | 241 return false; |
| 248 } | 242 } |
| 249 url->Swap(&temp_url); | 243 url->Swap(&temp_url); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 472 } |
| 479 | 473 |
| 480 return true; | 474 return true; |
| 481 } | 475 } |
| 482 | 476 |
| 483 void HistoryDeleteAllFunction::DeleteComplete() { | 477 void HistoryDeleteAllFunction::DeleteComplete() { |
| 484 SendAsyncResponse(); | 478 SendAsyncResponse(); |
| 485 } | 479 } |
| 486 | 480 |
| 487 } // namespace extensions | 481 } // namespace extensions |
| OLD | NEW |