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

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

Issue 21653002: Cleanups to the refactored extension activity log code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Clarify comments 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_log.h" 5 #include "chrome/browser/extensions/activity_log/activity_log.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (found) { 110 if (found) {
111 *url = contents->GetURL(); 111 *url = contents->GetURL();
112 *is_incognito = browser->profile()->IsOffTheRecord(); 112 *is_incognito = browser->profile()->IsOffTheRecord();
113 return true; 113 return true;
114 } else { 114 } else {
115 return false; 115 return false;
116 } 116 }
117 } 117 }
118 118
119 // Translate tab IDs to URLs in tabs API calls. Mutates the Action object in 119 // Translate tab IDs to URLs in tabs API calls. Mutates the Action object in
120 // place. Translate tab IDs to URLs in tabs API calls. It will swap out the 120 // place. There is a small chance that the URL translation could be wrong, if
121 // int in args with a URL as a string. There is a small chance that the URL 121 // the tab has already been navigated by the time of invocation.
122 // translation could be wrong, if the tab has already been navigated by the 122 //
123 // time of invocation. 123 // If a single tab ID is translated to a URL, the URL is stored into arg_url
124 // where it can more easily be searched for in the database. For APIs that
125 // take a list of tab IDs, replace each tab ID with the URL in the argument
126 // list; we can only extract a single URL into arg_url so arbitrarily pull out
127 // the first one.
124 void LookupTabIds(scoped_refptr<extensions::Action> action, Profile* profile) { 128 void LookupTabIds(scoped_refptr<extensions::Action> action, Profile* profile) {
125 const std::string& api_call = action->api_name(); 129 const std::string& api_call = action->api_name();
126 if (api_call == "tabs.get" || // api calls, ID as int 130 if (api_call == "tabs.get" || // api calls, ID as int
127 api_call == "tabs.connect" || 131 api_call == "tabs.connect" ||
128 api_call == "tabs.sendMessage" || 132 api_call == "tabs.sendMessage" ||
129 api_call == "tabs.duplicate" || 133 api_call == "tabs.duplicate" ||
130 api_call == "tabs.update" || 134 api_call == "tabs.update" ||
131 api_call == "tabs.reload" || 135 api_call == "tabs.reload" ||
132 api_call == "tabs.detectLanguage" || 136 api_call == "tabs.detectLanguage" ||
133 api_call == "tabs.executeScript" || 137 api_call == "tabs.executeScript" ||
134 api_call == "tabs.insertCSS" || 138 api_call == "tabs.insertCSS" ||
135 api_call == "tabs.move" || // api calls, IDs in array 139 api_call == "tabs.move" || // api calls, IDs in array
136 api_call == "tabs.remove" || 140 api_call == "tabs.remove" ||
137 api_call == "tabs.onUpdated" || // events, ID as int 141 api_call == "tabs.onUpdated" || // events, ID as int
138 api_call == "tabs.onMoved" || 142 api_call == "tabs.onMoved" ||
139 api_call == "tabs.onDetached" || 143 api_call == "tabs.onDetached" ||
140 api_call == "tabs.onAttached" || 144 api_call == "tabs.onAttached" ||
141 api_call == "tabs.onRemoved" || 145 api_call == "tabs.onRemoved" ||
142 api_call == "tabs.onReplaced") { 146 api_call == "tabs.onReplaced") {
143 int tab_id; 147 int tab_id;
144 base::ListValue* id_list; 148 base::ListValue* id_list;
145 base::ListValue* args = action->mutable_args(); 149 base::ListValue* args = action->mutable_args();
146 if (args->GetInteger(0, &tab_id)) { 150 if (args->GetInteger(0, &tab_id)) {
151 // Single tab ID to translate.
147 GURL url; 152 GURL url;
148 bool is_incognito; 153 bool is_incognito;
149 if (GetUrlForTabId(tab_id, profile, &url, &is_incognito)) { 154 if (GetUrlForTabId(tab_id, profile, &url, &is_incognito)) {
150 action->set_arg_url(url); 155 action->set_arg_url(url);
151 action->set_arg_incognito(is_incognito); 156 action->set_arg_incognito(is_incognito);
152 } 157 }
153 } else if ((api_call == "tabs.move" || api_call == "tabs.remove") && 158 } else if ((api_call == "tabs.move" || api_call == "tabs.remove") &&
154 args->GetList(0, &id_list)) { 159 args->GetList(0, &id_list)) {
160 // Array of tab IDs to translate.
155 for (int i = 0; i < static_cast<int>(id_list->GetSize()); ++i) { 161 for (int i = 0; i < static_cast<int>(id_list->GetSize()); ++i) {
156 if (id_list->GetInteger(i, &tab_id)) { 162 if (id_list->GetInteger(i, &tab_id)) {
157 GURL url; 163 GURL url;
158 bool is_incognito; 164 bool is_incognito;
159 if (GetUrlForTabId(tab_id, profile, &url, &is_incognito) && 165 if (GetUrlForTabId(tab_id, profile, &url, &is_incognito) &&
160 !is_incognito) 166 !is_incognito) {
161 id_list->Set(i, new base::StringValue(url.spec())); 167 id_list->Set(i, new base::StringValue(url.spec()));
168 if (i == 0) {
169 action->set_arg_url(url);
170 action->set_arg_incognito(is_incognito);
171 }
172 }
162 } else { 173 } else {
163 LOG(ERROR) << "The tab ID array is malformed at index " << i; 174 LOG(ERROR) << "The tab ID array is malformed at index " << i;
164 } 175 }
165 } 176 }
166 } 177 }
167 } 178 }
168 } 179 }
169 180
170 } // namespace 181 } // namespace
171 182
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 it2 != it->second.end(); 420 it2 != it->second.end();
410 ++it2) { 421 ++it2) {
411 action->mutable_args()->AppendString(*it2); 422 action->mutable_args()->AppendString(*it2);
412 } 423 }
413 LogAction(action); 424 LogAction(action);
414 } 425 }
415 } 426 }
416 } 427 }
417 428
418 } // namespace extensions 429 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698