| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 scoped_ptr<HistoryItem> history_item(new HistoryItem()); | 66 scoped_ptr<HistoryItem> history_item(new HistoryItem()); |
| 65 | 67 |
| 66 history_item->id = base::Int64ToString(row.id()); | 68 history_item->id = base::Int64ToString(row.id()); |
| 67 history_item->url.reset(new std::string(row.url().spec())); | 69 history_item->url.reset(new std::string(row.url().spec())); |
| 68 history_item->title.reset(new std::string(base::UTF16ToUTF8(row.title()))); | 70 history_item->title.reset(new std::string(base::UTF16ToUTF8(row.title()))); |
| 69 history_item->last_visit_time.reset( | 71 history_item->last_visit_time.reset( |
| 70 new double(MilliSecondsFromTime(row.last_visit()))); | 72 new double(MilliSecondsFromTime(row.last_visit()))); |
| 71 history_item->typed_count.reset(new int(row.typed_count())); | 73 history_item->typed_count.reset(new int(row.typed_count())); |
| 72 history_item->visit_count.reset(new int(row.visit_count())); | 74 history_item->visit_count.reset(new int(row.visit_count())); |
| 73 | 75 |
| 74 return history_item.Pass(); | 76 return history_item; |
| 75 } | 77 } |
| 76 | 78 |
| 77 scoped_ptr<VisitItem> GetVisitItem(const history::VisitRow& row) { | 79 scoped_ptr<VisitItem> GetVisitItem(const history::VisitRow& row) { |
| 78 scoped_ptr<VisitItem> visit_item(new VisitItem()); | 80 scoped_ptr<VisitItem> visit_item(new VisitItem()); |
| 79 | 81 |
| 80 visit_item->id = base::Int64ToString(row.url_id); | 82 visit_item->id = base::Int64ToString(row.url_id); |
| 81 visit_item->visit_id = base::Int64ToString(row.visit_id); | 83 visit_item->visit_id = base::Int64ToString(row.visit_id); |
| 82 visit_item->visit_time.reset( | 84 visit_item->visit_time.reset( |
| 83 new double(MilliSecondsFromTime(row.visit_time))); | 85 new double(MilliSecondsFromTime(row.visit_time))); |
| 84 visit_item->referring_visit_id = base::Int64ToString(row.referring_visit); | 86 visit_item->referring_visit_id = base::Int64ToString(row.referring_visit); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 break; | 119 break; |
| 118 case ui::PAGE_TRANSITION_KEYWORD_GENERATED: | 120 case ui::PAGE_TRANSITION_KEYWORD_GENERATED: |
| 119 transition = api::history::TRANSITION_TYPE_KEYWORD_GENERATED; | 121 transition = api::history::TRANSITION_TYPE_KEYWORD_GENERATED; |
| 120 break; | 122 break; |
| 121 default: | 123 default: |
| 122 DCHECK(false); | 124 DCHECK(false); |
| 123 } | 125 } |
| 124 | 126 |
| 125 visit_item->transition = transition; | 127 visit_item->transition = transition; |
| 126 | 128 |
| 127 return visit_item.Pass(); | 129 return visit_item; |
| 128 } | 130 } |
| 129 | 131 |
| 130 } // namespace | 132 } // namespace |
| 131 | 133 |
| 132 HistoryEventRouter::HistoryEventRouter(Profile* profile, | 134 HistoryEventRouter::HistoryEventRouter(Profile* profile, |
| 133 history::HistoryService* history_service) | 135 history::HistoryService* history_service) |
| 134 : profile_(profile), history_service_observer_(this) { | 136 : profile_(profile), history_service_observer_(this) { |
| 135 DCHECK(profile); | 137 DCHECK(profile); |
| 136 history_service_observer_.Add(history_service); | 138 history_service_observer_.Add(history_service); |
| 137 } | 139 } |
| 138 | 140 |
| 139 HistoryEventRouter::~HistoryEventRouter() { | 141 HistoryEventRouter::~HistoryEventRouter() { |
| 140 } | 142 } |
| 141 | 143 |
| 142 void HistoryEventRouter::OnURLVisited(history::HistoryService* history_service, | 144 void HistoryEventRouter::OnURLVisited(history::HistoryService* history_service, |
| 143 ui::PageTransition transition, | 145 ui::PageTransition transition, |
| 144 const history::URLRow& row, | 146 const history::URLRow& row, |
| 145 const history::RedirectList& redirects, | 147 const history::RedirectList& redirects, |
| 146 base::Time visit_time) { | 148 base::Time visit_time) { |
| 147 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); | 149 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); |
| 148 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); | 150 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); |
| 149 DispatchEvent(profile_, events::HISTORY_ON_VISITED, | 151 DispatchEvent(profile_, events::HISTORY_ON_VISITED, |
| 150 api::history::OnVisited::kEventName, args.Pass()); | 152 api::history::OnVisited::kEventName, std::move(args)); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void HistoryEventRouter::OnURLsDeleted(history::HistoryService* history_service, | 155 void HistoryEventRouter::OnURLsDeleted(history::HistoryService* history_service, |
| 154 bool all_history, | 156 bool all_history, |
| 155 bool expired, | 157 bool expired, |
| 156 const history::URLRows& deleted_rows, | 158 const history::URLRows& deleted_rows, |
| 157 const std::set<GURL>& favicon_urls) { | 159 const std::set<GURL>& favicon_urls) { |
| 158 OnVisitRemoved::Removed removed; | 160 OnVisitRemoved::Removed removed; |
| 159 removed.all_history = all_history; | 161 removed.all_history = all_history; |
| 160 | 162 |
| 161 std::vector<std::string>* urls = new std::vector<std::string>(); | 163 std::vector<std::string>* urls = new std::vector<std::string>(); |
| 162 for (const auto& row : deleted_rows) | 164 for (const auto& row : deleted_rows) |
| 163 urls->push_back(row.url().spec()); | 165 urls->push_back(row.url().spec()); |
| 164 removed.urls.reset(urls); | 166 removed.urls.reset(urls); |
| 165 | 167 |
| 166 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed); | 168 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed); |
| 167 DispatchEvent(profile_, events::HISTORY_ON_VISIT_REMOVED, | 169 DispatchEvent(profile_, events::HISTORY_ON_VISIT_REMOVED, |
| 168 api::history::OnVisitRemoved::kEventName, args.Pass()); | 170 api::history::OnVisitRemoved::kEventName, std::move(args)); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void HistoryEventRouter::DispatchEvent(Profile* profile, | 173 void HistoryEventRouter::DispatchEvent(Profile* profile, |
| 172 events::HistogramValue histogram_value, | 174 events::HistogramValue histogram_value, |
| 173 const std::string& event_name, | 175 const std::string& event_name, |
| 174 scoped_ptr<base::ListValue> event_args) { | 176 scoped_ptr<base::ListValue> event_args) { |
| 175 if (profile && EventRouter::Get(profile)) { | 177 if (profile && EventRouter::Get(profile)) { |
| 176 scoped_ptr<Event> event( | 178 scoped_ptr<Event> event( |
| 177 new Event(histogram_value, event_name, event_args.Pass())); | 179 new Event(histogram_value, event_name, std::move(event_args))); |
| 178 event->restrict_to_browser_context = profile; | 180 event->restrict_to_browser_context = profile; |
| 179 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 181 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
| 180 } | 182 } |
| 181 } | 183 } |
| 182 | 184 |
| 183 HistoryAPI::HistoryAPI(content::BrowserContext* context) | 185 HistoryAPI::HistoryAPI(content::BrowserContext* context) |
| 184 : browser_context_(context) { | 186 : browser_context_(context) { |
| 185 EventRouter* event_router = EventRouter::Get(browser_context_); | 187 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 186 event_router->RegisterObserver(this, api::history::OnVisited::kEventName); | 188 event_router->RegisterObserver(this, api::history::OnVisited::kEventName); |
| 187 event_router->RegisterObserver(this, | 189 event_router->RegisterObserver(this, |
| 188 api::history::OnVisitRemoved::kEventName); | 190 api::history::OnVisitRemoved::kEventName); |
| 189 } | 191 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 459 } |
| 458 | 460 |
| 459 return true; | 461 return true; |
| 460 } | 462 } |
| 461 | 463 |
| 462 void HistoryDeleteAllFunction::DeleteComplete() { | 464 void HistoryDeleteAllFunction::DeleteComplete() { |
| 463 SendAsyncResponse(); | 465 SendAsyncResponse(); |
| 464 } | 466 } |
| 465 | 467 |
| 466 } // namespace extensions | 468 } // namespace extensions |
| OLD | NEW |