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

Side by Side Diff: chrome/browser/history/history_extension_api.cc

Issue 9721013: Move topSites API out of experimental (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changes to reflect revision 127555 Created 8 years, 9 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
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 #include "chrome/browser/history/history_extension_api.h" 5 #include "chrome/browser/history/history_extension_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/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/cancelable_request.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/history/history.h" 16 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_types.h" 17 #include "chrome/browser/history/history_types.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
19 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
21 22
22 namespace { 23 namespace {
23 24
24 const char kAllHistoryKey[] = "allHistory"; 25 const char kAllHistoryKey[] = "allHistory";
25 const char kEndTimeKey[] = "endTime"; 26 const char kEndTimeKey[] = "endTime";
26 const char kFaviconUrlKey[] = "favIconUrl"; 27 const char kFaviconUrlKey[] = "favIconUrl";
27 const char kIdKey[] = "id"; 28 const char kIdKey[] = "id";
28 const char kLastVisitdKey[] = "lastVisitTime"; 29 const char kLastVisitdKey[] = "lastVisitTime";
29 const char kMaxResultsKey[] = "maxResults"; 30 const char kMaxResultsKey[] = "maxResults";
30 const char kNewKey[] = "new"; 31 const char kNewKey[] = "new";
31 const char kReferringVisitId[] = "referringVisitId"; 32 const char kReferringVisitId[] = "referringVisitId";
32 const char kRemovedKey[] = "removed"; 33 const char kRemovedKey[] = "removed";
33 const char kStartTimeKey[] = "startTime"; 34 const char kStartTimeKey[] = "startTime";
34 const char kTextKey[] = "text"; 35 const char kTextKey[] = "text";
35 const char kTitleKey[] = "title"; 36 const char kTitleKey[] = "title";
36 const char kTypedCountKey[] = "typedCount"; 37 const char kTypedCountKey[] = "typedCount";
37 const char kVisitCountKey[] = "visitCount"; 38 const char kVisitCountKey[] = "visitCount";
38 const char kTransition[] = "transition"; 39 const char kTransition[] = "transition";
39 const char kUrlKey[] = "url"; 40 const char kUrlKey[] = "url";
40 const char kUrlsKey[] = "urls"; 41 const char kUrlsKey[] = "urls";
41 const char kVisitId[] = "visitId"; 42 const char kVisitId[] = "visitId";
42 const char kVisitTime[] = "visitTime"; 43 const char kVisitTime[] = "visitTime";
44 const char kRedirectsKey[] = "redirects";
43 45
44 const char kOnVisited[] = "history.onVisited"; 46 const char kOnVisited[] = "history.onVisited";
45 const char kOnVisitRemoved[] = "history.onVisitRemoved"; 47 const char kOnVisitRemoved[] = "history.onVisitRemoved";
46 48
47 const char kInvalidIdError[] = "History item id is invalid."; 49 const char kInvalidIdError[] = "History item id is invalid.";
48 const char kInvalidUrlError[] = "Url is invalid."; 50 const char kInvalidUrlError[] = "Url is invalid.";
49 51
52 const int kDaysOfHistory = 90;
53
50 double MilliSecondsFromTime(const base::Time& time) { 54 double MilliSecondsFromTime(const base::Time& time) {
51 return 1000 * time.ToDoubleT(); 55 return 1000 * time.ToDoubleT();
52 } 56 }
53 57
54 void GetHistoryItemDictionary(const history::URLRow& row, 58 void GetHistoryItemDictionary(const history::URLRow& row,
55 DictionaryValue* value) { 59 DictionaryValue* value) {
56 value->SetString(kIdKey, base::Int64ToString(row.id())); 60 value->SetString(kIdKey, base::Int64ToString(row.id()));
57 value->SetString(kUrlKey, row.url().spec()); 61 value->SetString(kUrlKey, row.url().spec());
58 value->SetString(kTitleKey, row.title()); 62 value->SetString(kTitleKey, row.title());
59 value->SetDouble(kLastVisitdKey, 63 value->SetDouble(kLastVisitdKey,
(...skipping 21 matching lines...) Expand all
81 DCHECK(trans) << "Invalid transition."; 85 DCHECK(trans) << "Invalid transition.";
82 value->SetString(kTransition, trans); 86 value->SetString(kTransition, trans);
83 } 87 }
84 88
85 void AddVisitNode(const history::VisitRow& row, ListValue* list) { 89 void AddVisitNode(const history::VisitRow& row, ListValue* list) {
86 DictionaryValue* dict = new DictionaryValue(); 90 DictionaryValue* dict = new DictionaryValue();
87 GetVisitInfoDictionary(row, dict); 91 GetVisitInfoDictionary(row, dict);
88 list->Append(dict); 92 list->Append(dict);
89 } 93 }
90 94
95 void AddMostVisitedNode(const history::MostVisitedURL& item, ListValue* list) {
96 DictionaryValue* dict = new DictionaryValue();
97 ListValue* redirect_list = new ListValue();
98 dict->SetString(kUrlKey, item.url.spec());
99 dict->SetString(kTitleKey, item.title);
100 for (history::RedirectList::const_iterator iterator = item.redirects.begin();
101 iterator != item.redirects.end(); ++iterator) {
102 StringValue* redirect = new StringValue((*iterator).spec());
103 redirect_list->Append(redirect);
104 }
105 dict->Set(kRedirectsKey, redirect_list);
106 list->Append(dict);
107 }
108
91 } // namespace 109 } // namespace
92 110
93 HistoryExtensionEventRouter::HistoryExtensionEventRouter() {} 111 HistoryExtensionEventRouter::HistoryExtensionEventRouter() {}
94 112
95 HistoryExtensionEventRouter::~HistoryExtensionEventRouter() {} 113 HistoryExtensionEventRouter::~HistoryExtensionEventRouter() {}
96 114
97 void HistoryExtensionEventRouter::ObserveProfile(Profile* profile) { 115 void HistoryExtensionEventRouter::ObserveProfile(Profile* profile) {
98 CHECK(registrar_.IsEmpty()); 116 CHECK(registrar_.IsEmpty());
99 const content::Source<Profile> source = content::Source<Profile>(profile); 117 const content::Source<Profile> source = content::Source<Profile>(profile);
100 registrar_.Add(this, 118 registrar_.Add(this,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 &cancelable_consumer_, 411 &cancelable_consumer_,
394 base::Bind(&DeleteAllHistoryFunction::DeleteComplete, 412 base::Bind(&DeleteAllHistoryFunction::DeleteComplete,
395 base::Unretained(this))); 413 base::Unretained(this)));
396 414
397 return true; 415 return true;
398 } 416 }
399 417
400 void DeleteAllHistoryFunction::DeleteComplete() { 418 void DeleteAllHistoryFunction::DeleteComplete() {
401 SendAsyncResponse(); 419 SendAsyncResponse();
402 } 420 }
421
422 bool GetMostVisitedHistoryFunction::RunAsyncImpl() {
423 DictionaryValue* json = NULL;
424 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
425
426 Value* value = NULL;
427 int how_many = 0;
428 EXTENSION_FUNCTION_VALIDATE(json->Get(kMaxResultsKey, &value));
429 value->GetAsInteger(&how_many);
430
431 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
432 hs->QueryMostVisitedURLs(
433 how_many,
434 kDaysOfHistory,
Aaron Boodman 2012/03/20 02:24:24 Why not allow developers to specify this too. You
435 &history_consumer_,
436 base::Bind(&GetMostVisitedHistoryFunction::QueryComplete,
437 base::Unretained(this)));
438 return true;
439 }
440
441 void GetMostVisitedHistoryFunction::QueryComplete(
442 CancelableRequestProvider::Handle handle,
443 history::MostVisitedURLList pages) {
444 ListValue* list = new ListValue();
445 for (history::MostVisitedURLList::const_iterator iterator = pages.begin();
446 iterator != pages.end();
447 ++iterator) {
Aaron Boodman 2012/03/20 02:24:24 This can go on previous line.
448 AddMostVisitedNode(*iterator, list);
449 }
450 result_.reset(list);
451 SendAsyncResponse();
452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698