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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 1853573002: [Extensions] Remove 'use_movable_types' from code generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/cc_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
Devlin 2016/04/01 01:38:24 Missed this one because the json has "compler_opti
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> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
(...skipping 20 matching lines...) Expand all
32 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "extensions/browser/event_router.h" 33 #include "extensions/browser/event_router.h"
34 #include "extensions/browser/extension_system_provider.h" 34 #include "extensions/browser/extension_system_provider.h"
35 #include "extensions/browser/extensions_browser_client.h" 35 #include "extensions/browser/extensions_browser_client.h"
36 36
37 namespace extensions { 37 namespace extensions {
38 38
39 using api::history::HistoryItem; 39 using api::history::HistoryItem;
40 using api::history::VisitItem; 40 using api::history::VisitItem;
41 41
42 typedef std::vector<linked_ptr<api::history::HistoryItem> > 42 typedef std::vector<api::history::HistoryItem> HistoryItemList;
43 HistoryItemList; 43 typedef std::vector<api::history::VisitItem> VisitItemList;
44 typedef std::vector<linked_ptr<api::history::VisitItem> >
45 VisitItemList;
46 44
47 namespace AddUrl = api::history::AddUrl; 45 namespace AddUrl = api::history::AddUrl;
48 namespace DeleteUrl = api::history::DeleteUrl; 46 namespace DeleteUrl = api::history::DeleteUrl;
49 namespace DeleteRange = api::history::DeleteRange; 47 namespace DeleteRange = api::history::DeleteRange;
50 namespace GetVisits = api::history::GetVisits; 48 namespace GetVisits = api::history::GetVisits;
51 namespace OnVisited = api::history::OnVisited; 49 namespace OnVisited = api::history::OnVisited;
52 namespace OnVisitRemoved = api::history::OnVisitRemoved; 50 namespace OnVisitRemoved = api::history::OnVisitRemoved;
53 namespace Search = api::history::Search; 51 namespace Search = api::history::Search;
54 52
55 namespace { 53 namespace {
56 54
57 const char kInvalidUrlError[] = "Url is invalid."; 55 const char kInvalidUrlError[] = "Url is invalid.";
58 const char kDeleteProhibitedError[] = "Browsing history is not allowed to be " 56 const char kDeleteProhibitedError[] = "Browsing history is not allowed to be "
59 "deleted."; 57 "deleted.";
60 58
61 double MilliSecondsFromTime(const base::Time& time) { 59 double MilliSecondsFromTime(const base::Time& time) {
62 return 1000 * time.ToDoubleT(); 60 return 1000 * time.ToDoubleT();
63 } 61 }
64 62
65 scoped_ptr<HistoryItem> GetHistoryItem(const history::URLRow& row) { 63 HistoryItem GetHistoryItem(const history::URLRow& row) {
66 scoped_ptr<HistoryItem> history_item(new HistoryItem()); 64 HistoryItem history_item;
67 65
68 history_item->id = base::Int64ToString(row.id()); 66 history_item.id = base::Int64ToString(row.id());
69 history_item->url.reset(new std::string(row.url().spec())); 67 history_item.url.reset(new std::string(row.url().spec()));
70 history_item->title.reset(new std::string(base::UTF16ToUTF8(row.title()))); 68 history_item.title.reset(new std::string(base::UTF16ToUTF8(row.title())));
71 history_item->last_visit_time.reset( 69 history_item.last_visit_time.reset(
72 new double(MilliSecondsFromTime(row.last_visit()))); 70 new double(MilliSecondsFromTime(row.last_visit())));
73 history_item->typed_count.reset(new int(row.typed_count())); 71 history_item.typed_count.reset(new int(row.typed_count()));
74 history_item->visit_count.reset(new int(row.visit_count())); 72 history_item.visit_count.reset(new int(row.visit_count()));
75 73
76 return history_item; 74 return history_item;
77 } 75 }
78 76
79 scoped_ptr<VisitItem> GetVisitItem(const history::VisitRow& row) { 77 VisitItem GetVisitItem(const history::VisitRow& row) {
80 scoped_ptr<VisitItem> visit_item(new VisitItem()); 78 VisitItem visit_item;
81 79
82 visit_item->id = base::Int64ToString(row.url_id); 80 visit_item.id = base::Int64ToString(row.url_id);
83 visit_item->visit_id = base::Int64ToString(row.visit_id); 81 visit_item.visit_id = base::Int64ToString(row.visit_id);
84 visit_item->visit_time.reset( 82 visit_item.visit_time.reset(new double(MilliSecondsFromTime(row.visit_time)));
85 new double(MilliSecondsFromTime(row.visit_time))); 83 visit_item.referring_visit_id = base::Int64ToString(row.referring_visit);
86 visit_item->referring_visit_id = base::Int64ToString(row.referring_visit);
87 84
88 api::history::TransitionType transition = api::history::TRANSITION_TYPE_LINK; 85 api::history::TransitionType transition = api::history::TRANSITION_TYPE_LINK;
89 switch (row.transition & ui::PAGE_TRANSITION_CORE_MASK) { 86 switch (row.transition & ui::PAGE_TRANSITION_CORE_MASK) {
90 case ui::PAGE_TRANSITION_LINK: 87 case ui::PAGE_TRANSITION_LINK:
91 transition = api::history::TRANSITION_TYPE_LINK; 88 transition = api::history::TRANSITION_TYPE_LINK;
92 break; 89 break;
93 case ui::PAGE_TRANSITION_TYPED: 90 case ui::PAGE_TRANSITION_TYPED:
94 transition = api::history::TRANSITION_TYPE_TYPED; 91 transition = api::history::TRANSITION_TYPE_TYPED;
95 break; 92 break;
96 case ui::PAGE_TRANSITION_AUTO_BOOKMARK: 93 case ui::PAGE_TRANSITION_AUTO_BOOKMARK:
(...skipping 20 matching lines...) Expand all
117 case ui::PAGE_TRANSITION_KEYWORD: 114 case ui::PAGE_TRANSITION_KEYWORD:
118 transition = api::history::TRANSITION_TYPE_KEYWORD; 115 transition = api::history::TRANSITION_TYPE_KEYWORD;
119 break; 116 break;
120 case ui::PAGE_TRANSITION_KEYWORD_GENERATED: 117 case ui::PAGE_TRANSITION_KEYWORD_GENERATED:
121 transition = api::history::TRANSITION_TYPE_KEYWORD_GENERATED; 118 transition = api::history::TRANSITION_TYPE_KEYWORD_GENERATED;
122 break; 119 break;
123 default: 120 default:
124 DCHECK(false); 121 DCHECK(false);
125 } 122 }
126 123
127 visit_item->transition = transition; 124 visit_item.transition = transition;
128 125
129 return visit_item; 126 return visit_item;
130 } 127 }
131 128
132 } // namespace 129 } // namespace
133 130
134 HistoryEventRouter::HistoryEventRouter(Profile* profile, 131 HistoryEventRouter::HistoryEventRouter(Profile* profile,
135 history::HistoryService* history_service) 132 history::HistoryService* history_service)
136 : profile_(profile), history_service_observer_(this) { 133 : profile_(profile), history_service_observer_(this) {
137 DCHECK(profile); 134 DCHECK(profile);
138 history_service_observer_.Add(history_service); 135 history_service_observer_.Add(history_service);
139 } 136 }
140 137
141 HistoryEventRouter::~HistoryEventRouter() { 138 HistoryEventRouter::~HistoryEventRouter() {
142 } 139 }
143 140
144 void HistoryEventRouter::OnURLVisited(history::HistoryService* history_service, 141 void HistoryEventRouter::OnURLVisited(history::HistoryService* history_service,
145 ui::PageTransition transition, 142 ui::PageTransition transition,
146 const history::URLRow& row, 143 const history::URLRow& row,
147 const history::RedirectList& redirects, 144 const history::RedirectList& redirects,
148 base::Time visit_time) { 145 base::Time visit_time) {
149 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); 146 scoped_ptr<base::ListValue> args = OnVisited::Create(GetHistoryItem(row));
150 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item);
151 DispatchEvent(profile_, events::HISTORY_ON_VISITED, 147 DispatchEvent(profile_, events::HISTORY_ON_VISITED,
152 api::history::OnVisited::kEventName, std::move(args)); 148 api::history::OnVisited::kEventName, std::move(args));
153 } 149 }
154 150
155 void HistoryEventRouter::OnURLsDeleted(history::HistoryService* history_service, 151 void HistoryEventRouter::OnURLsDeleted(history::HistoryService* history_service,
156 bool all_history, 152 bool all_history,
157 bool expired, 153 bool expired,
158 const history::URLRows& deleted_rows, 154 const history::URLRows& deleted_rows,
159 const std::set<GURL>& favicon_urls) { 155 const std::set<GURL>& favicon_urls) {
160 OnVisitRemoved::Removed removed; 156 OnVisitRemoved::Removed removed;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 &task_tracker_); 288 &task_tracker_);
293 return true; 289 return true;
294 } 290 }
295 291
296 void HistoryGetVisitsFunction::QueryComplete( 292 void HistoryGetVisitsFunction::QueryComplete(
297 bool success, 293 bool success,
298 const history::URLRow& url_row, 294 const history::URLRow& url_row,
299 const history::VisitVector& visits) { 295 const history::VisitVector& visits) {
300 VisitItemList visit_item_vec; 296 VisitItemList visit_item_vec;
301 if (success && !visits.empty()) { 297 if (success && !visits.empty()) {
302 for (history::VisitVector::const_iterator iterator = visits.begin(); 298 for (const history::VisitRow& visit : visits)
303 iterator != visits.end(); 299 visit_item_vec.push_back(GetVisitItem(visit));
304 ++iterator) {
305 visit_item_vec.push_back(make_linked_ptr(
306 GetVisitItem(*iterator).release()));
307 }
308 } 300 }
309 301
310 results_ = GetVisits::Results::Create(visit_item_vec); 302 results_ = GetVisits::Results::Create(visit_item_vec);
311 SendAsyncResponse(); 303 SendAsyncResponse();
312 } 304 }
313 305
314 bool HistorySearchFunction::RunAsyncImpl() { 306 bool HistorySearchFunction::RunAsyncImpl() {
315 scoped_ptr<Search::Params> params(Search::Params::Create(*args_)); 307 scoped_ptr<Search::Params> params(Search::Params::Create(*args_));
316 EXTENSION_FUNCTION_VALIDATE(params.get()); 308 EXTENSION_FUNCTION_VALIDATE(params.get());
317 309
(...skipping 17 matching lines...) Expand all
335 base::Bind(&HistorySearchFunction::SearchComplete, 327 base::Bind(&HistorySearchFunction::SearchComplete,
336 base::Unretained(this)), 328 base::Unretained(this)),
337 &task_tracker_); 329 &task_tracker_);
338 330
339 return true; 331 return true;
340 } 332 }
341 333
342 void HistorySearchFunction::SearchComplete(history::QueryResults* results) { 334 void HistorySearchFunction::SearchComplete(history::QueryResults* results) {
343 HistoryItemList history_item_vec; 335 HistoryItemList history_item_vec;
344 if (results && !results->empty()) { 336 if (results && !results->empty()) {
345 for (history::QueryResults::URLResultVector::const_iterator iterator = 337 for (const history::URLResult* item : *results)
346 results->begin(); 338 history_item_vec.push_back(GetHistoryItem(*item));
347 iterator != results->end();
348 ++iterator) {
349 history_item_vec.push_back(make_linked_ptr(
350 GetHistoryItem(**iterator).release()));
351 }
352 } 339 }
353 results_ = Search::Results::Create(history_item_vec); 340 results_ = Search::Results::Create(history_item_vec);
354 SendAsyncResponse(); 341 SendAsyncResponse();
355 } 342 }
356 343
357 bool HistoryAddUrlFunction::RunAsync() { 344 bool HistoryAddUrlFunction::RunAsync() {
358 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_)); 345 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_));
359 EXTENSION_FUNCTION_VALIDATE(params.get()); 346 EXTENSION_FUNCTION_VALIDATE(params.get());
360 347
361 GURL url; 348 GURL url;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 446 }
460 447
461 return true; 448 return true;
462 } 449 }
463 450
464 void HistoryDeleteAllFunction::DeleteComplete() { 451 void HistoryDeleteAllFunction::DeleteComplete() {
465 SendAsyncResponse(); 452 SendAsyncResponse();
466 } 453 }
467 454
468 } // namespace extensions 455 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/cc_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698