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

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

Issue 480883002: Move session_id.{cc,h} from chrome/browser/sessions to components/sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/uma_policy.h" 5 #include "chrome/browser/extensions/activity_log/uma_policy.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/active_script_controller.h" 10 #include "chrome/browser/extensions/active_script_controller.h"
11 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" 11 #include "chrome/browser/extensions/activity_log/activity_action_constants.h"
12 #include "chrome/browser/extensions/activity_log/ad_network_database.h" 12 #include "chrome/browser/extensions/activity_log/ad_network_database.h"
13 #include "chrome/browser/sessions/session_id.h" 13 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/url_constants.h" 19 #include "content/public/common/url_constants.h"
20 #include "extensions/browser/extension_registry.h" 20 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/dom_action_types.h" 21 #include "extensions/common/dom_action_types.h"
22 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
23 #include "extensions/common/manifest.h" 23 #include "extensions/common/manifest.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return; 309 return;
310 browser->tab_strip_model()->AddObserver(this); 310 browser->tab_strip_model()->AddObserver(this);
311 } 311 }
312 312
313 void UmaPolicy::OnBrowserRemoved(Browser* browser) { 313 void UmaPolicy::OnBrowserRemoved(Browser* browser) {
314 if (!profile_->IsSameProfile(browser->profile())) 314 if (!profile_->IsSameProfile(browser->profile()))
315 return; 315 return;
316 browser->tab_strip_model()->RemoveObserver(this); 316 browser->tab_strip_model()->RemoveObserver(this);
317 } 317 }
318 318
319 // Use the value from SessionID::IdForTab, *not* |index|. |index| will be 319 // Use the value from SessionTabHelper::IdForTab, *not* |index|. |index| will be
320 // duplicated across tabs in a session, whereas IdForTab uniquely identifies 320 // duplicated across tabs in a session, whereas IdForTab uniquely identifies
321 // each tab. 321 // each tab.
322 void UmaPolicy::TabChangedAt(content::WebContents* contents, 322 void UmaPolicy::TabChangedAt(content::WebContents* contents,
323 int index, 323 int index,
324 TabChangeType change_type) { 324 TabChangeType change_type) {
325 if (change_type != TabStripModelObserver::LOADING_ONLY) 325 if (change_type != TabStripModelObserver::LOADING_ONLY)
326 return; 326 return;
327 if (!contents) 327 if (!contents)
328 return; 328 return;
329 329
330 std::string url = CleanURL(contents->GetLastCommittedURL()); 330 std::string url = CleanURL(contents->GetLastCommittedURL());
331 int32 tab_id = SessionID::IdForTab(contents); 331 int32 tab_id = SessionTabHelper::IdForTab(contents);
332 332
333 std::map<int32, std::string>::iterator tab_it = tab_list_.find(tab_id); 333 std::map<int32, std::string>::iterator tab_it = tab_list_.find(tab_id);
334 334
335 // Ignore tabs that haven't changed status. 335 // Ignore tabs that haven't changed status.
336 if (tab_it != tab_list_.end() && tab_it->second == url) 336 if (tab_it != tab_list_.end() && tab_it->second == url)
337 return; 337 return;
338 338
339 // Is this an existing tab whose URL has changed. 339 // Is this an existing tab whose URL has changed.
340 if (tab_it != tab_list_.end()) { 340 if (tab_it != tab_list_.end()) {
341 CleanupClosedPage(tab_it->second, contents); 341 CleanupClosedPage(tab_it->second, contents);
342 tab_list_.erase(tab_id); 342 tab_list_.erase(tab_id);
343 } 343 }
344 344
345 // Check that tab_list_ isn't over the kMaxTabsTracked budget. 345 // Check that tab_list_ isn't over the kMaxTabsTracked budget.
346 if (tab_list_.size() >= kMaxTabsTracked) 346 if (tab_list_.size() >= kMaxTabsTracked)
347 return; 347 return;
348 348
349 // Set up the new entries. 349 // Set up the new entries.
350 tab_list_[tab_id] = url; 350 tab_list_[tab_id] = url;
351 SetupOpenedPage(url); 351 SetupOpenedPage(url);
352 } 352 }
353 353
354 // Use the value from SessionID::IdForTab, *not* |index|. |index| will be 354 // Use the value from SessionTabHelper::IdForTab, *not* |index|. |index| will be
355 // duplicated across tabs in a session, whereas IdForTab uniquely identifies 355 // duplicated across tabs in a session, whereas IdForTab uniquely identifies
356 // each tab. 356 // each tab.
357 void UmaPolicy::TabClosingAt(TabStripModel* tab_strip_model, 357 void UmaPolicy::TabClosingAt(TabStripModel* tab_strip_model,
358 content::WebContents* contents, 358 content::WebContents* contents,
359 int index) { 359 int index) {
360 if (!contents) 360 if (!contents)
361 return; 361 return;
362 std::string url = CleanURL(contents->GetLastCommittedURL()); 362 std::string url = CleanURL(contents->GetLastCommittedURL());
363 int32 tab_id = SessionID::IdForTab(contents); 363 int32 tab_id = SessionTabHelper::IdForTab(contents);
364 std::map<int, std::string>::iterator tab_it = tab_list_.find(tab_id); 364 std::map<int, std::string>::iterator tab_it = tab_list_.find(tab_id);
365 if (tab_it != tab_list_.end()) 365 if (tab_it != tab_list_.end())
366 tab_list_.erase(tab_id); 366 tab_list_.erase(tab_id);
367 367
368 CleanupClosedPage(url, contents); 368 CleanupClosedPage(url, contents);
369 } 369 }
370 370
371 void UmaPolicy::SetupOpenedPage(const std::string& url) { 371 void UmaPolicy::SetupOpenedPage(const std::string& url) {
372 url_status_[url][kNumberOfTabs]++; 372 url_status_[url][kNumberOfTabs]++;
373 } 373 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 return "AdLikelyReplaced"; 450 return "AdLikelyReplaced";
451 case NONE: 451 case NONE:
452 case MAX_STATUS: 452 case MAX_STATUS:
453 default: 453 default:
454 NOTREACHED(); 454 NOTREACHED();
455 return ""; 455 return "";
456 } 456 }
457 } 457 }
458 458
459 } // namespace extensions 459 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_tab_unittest.cc ('k') | chrome/browser/extensions/api/debugger/debugger_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698