OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_history_api.h" | 5 #include "chrome/browser/extensions/extension_history_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_history_api_constants.h" | 13 #include "chrome/browser/extensions/extension_history_api_constants.h" |
14 #include "chrome/browser/extensions/extension_message_service.h" | 14 #include "chrome/browser/extensions/extension_message_service.h" |
15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
16 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
17 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
18 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
19 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
20 | 20 |
21 namespace keys = extension_history_api_constants; | 21 namespace keys = extension_history_api_constants; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 double MilliSecondsFromTime(const base::Time& time) { | 25 double MilliSecondsFromTime(const base::Time& time) { |
26 return 1000 * time.ToDoubleT(); | 26 return 1000 * time.ToDoubleT(); |
27 } | 27 } |
28 | 28 |
29 void GetHistoryItemDictionary(const history::URLRow& row, | 29 void GetHistoryItemDictionary(const history::URLRow& row, |
30 DictionaryValue* value) { | 30 DictionaryValue* value) { |
31 value->SetString(keys::kIdKey, Int64ToString(row.id())); | 31 value->SetString(keys::kIdKey, base::Int64ToString(row.id())); |
32 value->SetString(keys::kUrlKey, row.url().spec()); | 32 value->SetString(keys::kUrlKey, row.url().spec()); |
33 value->SetStringFromUTF16(keys::kTitleKey, row.title()); | 33 value->SetStringFromUTF16(keys::kTitleKey, row.title()); |
34 value->SetReal(keys::kLastVisitdKey, MilliSecondsFromTime(row.last_visit())); | 34 value->SetReal(keys::kLastVisitdKey, MilliSecondsFromTime(row.last_visit())); |
35 value->SetInteger(keys::kTypedCountKey, row.typed_count()); | 35 value->SetInteger(keys::kTypedCountKey, row.typed_count()); |
36 value->SetInteger(keys::kVisitCountKey, row.visit_count()); | 36 value->SetInteger(keys::kVisitCountKey, row.visit_count()); |
37 } | 37 } |
38 | 38 |
39 void AddHistoryNode(const history::URLRow& row, ListValue* list) { | 39 void AddHistoryNode(const history::URLRow& row, ListValue* list) { |
40 DictionaryValue* dict = new DictionaryValue(); | 40 DictionaryValue* dict = new DictionaryValue(); |
41 GetHistoryItemDictionary(row, dict); | 41 GetHistoryItemDictionary(row, dict); |
42 list->Append(dict); | 42 list->Append(dict); |
43 } | 43 } |
44 | 44 |
45 void GetVisitInfoDictionary(const history::VisitRow& row, | 45 void GetVisitInfoDictionary(const history::VisitRow& row, |
46 DictionaryValue* value) { | 46 DictionaryValue* value) { |
47 value->SetString(keys::kIdKey, Int64ToString(row.url_id)); | 47 value->SetString(keys::kIdKey, base::Int64ToString(row.url_id)); |
48 value->SetString(keys::kVisitId, Int64ToString(row.visit_id)); | 48 value->SetString(keys::kVisitId, base::Int64ToString(row.visit_id)); |
49 value->SetReal(keys::kVisitTime, MilliSecondsFromTime(row.visit_time)); | 49 value->SetReal(keys::kVisitTime, MilliSecondsFromTime(row.visit_time)); |
50 value->SetString(keys::kReferringVisitId, | 50 value->SetString(keys::kReferringVisitId, |
51 Int64ToString(row.referring_visit)); | 51 base::Int64ToString(row.referring_visit)); |
52 | 52 |
53 const char* trans = PageTransition::CoreTransitionString(row.transition); | 53 const char* trans = PageTransition::CoreTransitionString(row.transition); |
54 DCHECK(trans) << "Invalid transition."; | 54 DCHECK(trans) << "Invalid transition."; |
55 value->SetString(keys::kTransition, trans); | 55 value->SetString(keys::kTransition, trans); |
56 } | 56 } |
57 | 57 |
58 void AddVisitNode(const history::VisitRow& row, ListValue* list) { | 58 void AddVisitNode(const history::VisitRow& row, ListValue* list) { |
59 DictionaryValue* dict = new DictionaryValue(); | 59 DictionaryValue* dict = new DictionaryValue(); |
60 GetVisitInfoDictionary(row, dict); | 60 GetVisitInfoDictionary(row, dict); |
61 list->Append(dict); | 61 list->Append(dict); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 base::Time::Now(), // To the current time. | 367 base::Time::Now(), // To the current time. |
368 &cancelable_consumer_, | 368 &cancelable_consumer_, |
369 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); | 369 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); |
370 | 370 |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 void DeleteAllHistoryFunction::DeleteComplete() { | 374 void DeleteAllHistoryFunction::DeleteComplete() { |
375 SendAsyncResponse(); | 375 SendAsyncResponse(); |
376 } | 376 } |
OLD | NEW |