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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_actions.cc

Issue 21646004: Compressed activity log database storage (Closed) Base URL: http://git.chromium.org/chromium/src.git@refactor-cleanups
Patch Set: Factor out dropping of obsolete tables and use in all policies Created 7 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/activity_log/activity_actions.h" 5 #include "chrome/browser/extensions/activity_log/activity_actions.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" 15 #include "chrome/browser/extensions/activity_log/activity_action_constants.h"
16 #include "chrome/browser/extensions/activity_log/api_name_constants.h"
17 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" 16 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
18 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #include "sql/statement.h" 21 #include "sql/statement.h"
23 22
24 namespace constants = activity_log_constants; 23 namespace constants = activity_log_constants;
25 24
26 namespace { 25 namespace {
27 26
28 std::string Serialize(const base::Value* value) { 27 std::string Serialize(const base::Value* value) {
29 std::string value_as_text; 28 std::string value_as_text;
30 if (!value) { 29 if (!value) {
31 value_as_text = "null"; 30 value_as_text = "null";
32 } else { 31 } else {
33 JSONStringValueSerializer serializer(&value_as_text); 32 JSONStringValueSerializer serializer(&value_as_text);
34 serializer.SerializeAndOmitBinaryValues(*value); 33 serializer.SerializeAndOmitBinaryValues(*value);
35 } 34 }
36 return value_as_text; 35 return value_as_text;
37 } 36 }
38 37
39 // Sets up the hashmap for mapping extension strings to "ints". The hashmap is
40 // only set up once because it's quite long; the value is then cached.
41 class APINameMap {
42 public:
43 APINameMap() {
44 SetupMap();
45 }
46
47 // activity_log_api_name_constants.h lists all known API calls as of 5/17.
48 // This code maps each of those API calls (and events) to short strings
49 // (integers converted to strings). They're all strings because (1) sqlite
50 // databases are all strings underneath anyway and (2) the Lookup function
51 // will simply return the original api_call string if we don't have it in our
52 // lookup table.
53 void SetupMap() {
54 for (size_t i = 0;
55 i < arraysize(activity_log_api_name_constants::kNames);
56 ++i) {
57 std::string name =
58 std::string(activity_log_api_name_constants::kNames[i]);
59 std::string num = base::IntToString(i);
60 names_to_nums_[name] = num;
61 nums_to_names_[num] = name;
62 }
63 }
64
65 static APINameMap* GetInstance() {
66 return Singleton<APINameMap>::get();
67 }
68
69 // This matches an api call to a number, if it's in the lookup table. If not,
70 // it returns the original api call.
71 const std::string& ApiToShortname(const std::string& api_call) {
72 std::map<std::string, std::string>::iterator it =
73 names_to_nums_.find(api_call);
74 if (it == names_to_nums_.end())
75 return api_call;
76 else
77 return it->second;
78 }
79
80 // This matches a number to an API call -- it's the opposite of
81 // ApiToShortname.
82 const std::string& ShortnameToApi(const std::string& shortname) {
83 std::map<std::string, std::string>::iterator it =
84 nums_to_names_.find(shortname);
85 if (it == nums_to_names_.end())
86 return shortname;
87 else
88 return it->second;
89 }
90
91 private:
92 std::map<std::string, std::string> names_to_nums_; // <name, number label>
93 std::map<std::string, std::string> nums_to_names_; // <number label, name>
94 };
95
96 } // namespace 38 } // namespace
97 39
98 namespace extensions { 40 namespace extensions {
99 41
100 using api::activity_log_private::BlockedChromeActivityDetail; 42 using api::activity_log_private::BlockedChromeActivityDetail;
101 using api::activity_log_private::ChromeActivityDetail; 43 using api::activity_log_private::ChromeActivityDetail;
102 using api::activity_log_private::DomActivityDetail; 44 using api::activity_log_private::DomActivityDetail;
103 using api::activity_log_private::ExtensionActivity; 45 using api::activity_log_private::ExtensionActivity;
104 46
105 Action::Action(const std::string& extension_id, 47 Action::Action(const std::string& extension_id,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 181 }
240 182
241 default: 183 default:
242 LOG(WARNING) << "Bad activity log entry read from database (type=" 184 LOG(WARNING) << "Bad activity log entry read from database (type="
243 << action_type_ << ")!"; 185 << action_type_ << ")!";
244 } 186 }
245 187
246 return result.Pass(); 188 return result.Pass();
247 } 189 }
248 190
249 std::string Action::PrintForDebug() { 191 std::string Action::PrintForDebug() const {
250 std::string result = "ID=" + extension_id() + " CATEGORY="; 192 std::string result = "ID=" + extension_id() + " CATEGORY=";
251 switch (action_type_) { 193 switch (action_type_) {
252 case ACTION_API_CALL: 194 case ACTION_API_CALL:
253 result += "api_call"; 195 result += "api_call";
254 break; 196 break;
255 case ACTION_API_EVENT: 197 case ACTION_API_EVENT:
256 result += "api_event_callback"; 198 result += "api_event_callback";
257 break; 199 break;
258 case ACTION_WEB_REQUEST: 200 case ACTION_WEB_REQUEST:
259 result += "webrequest"; 201 result += "webrequest";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 result += " ARG_URL=" + arg_url_.spec(); 237 result += " ARG_URL=" + arg_url_.spec();
296 } 238 }
297 if (other_.get()) { 239 if (other_.get()) {
298 result += " OTHER=" + Serialize(other_.get()); 240 result += " OTHER=" + Serialize(other_.get());
299 } 241 }
300 242
301 return result; 243 return result;
302 } 244 }
303 245
304 } // namespace extensions 246 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698