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

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

Issue 155183002: Add ApiActivityMonitor to decouple ActivityLog from low-level extensions code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase3 (activity_log) Created 6 years, 10 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 (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"
11 #include "base/json/json_string_value_serializer.h" 11 #include "base/json/json_string_value_serializer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" 16 #include "chrome/browser/extensions/activity_log/activity_action_constants.h"
17 #include "chrome/browser/extensions/activity_log/counting_policy.h" 17 #include "chrome/browser/extensions/activity_log/counting_policy.h"
18 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" 18 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
19 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" 19 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system_factory.h" 21 #include "chrome/browser/extensions/extension_system_factory.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 22 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/extensions/install_tracker.h"
23 #include "chrome/browser/extensions/install_tracker_factory.h" 24 #include "chrome/browser/extensions/install_tracker_factory.h"
24 #include "chrome/browser/prefs/pref_service_syncable.h" 25 #include "chrome/browser/prefs/pref_service_syncable.h"
25 #include "chrome/browser/prerender/prerender_manager.h" 26 #include "chrome/browser/prerender/prerender_manager.h"
26 #include "chrome/browser/prerender/prerender_manager_factory.h" 27 #include "chrome/browser/prerender/prerender_manager_factory.h"
27 #include "chrome/browser/profiles/incognito_helpers.h" 28 #include "chrome/browser/profiles/incognito_helpers.h"
29 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
29 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
32 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 34 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
35 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
34 #include "extensions/browser/extension_system.h" 37 #include "extensions/browser/extension_system.h"
38 #include "extensions/browser/extensions_browser_client.h"
35 #include "extensions/common/extension.h" 39 #include "extensions/common/extension.h"
36 #include "third_party/re2/re2/re2.h" 40 #include "third_party/re2/re2/re2.h"
37 #include "url/gurl.h" 41 #include "url/gurl.h"
38 42
39 #if !defined(OS_ANDROID) 43 #if !defined(OS_ANDROID)
40 #include "chrome/browser/extensions/activity_log/uma_policy.h" 44 #include "chrome/browser/extensions/activity_log/uma_policy.h"
41 #endif 45 #endif
42 46
43 namespace constants = activity_log_constants; 47 namespace constants = activity_log_constants;
44 48
45 namespace { 49 namespace {
46 50
47 using extensions::Action; 51 using extensions::Action;
48 using constants::kArgUrlPlaceholder; 52 using constants::kArgUrlPlaceholder;
53 using content::BrowserThread;
49 54
50 // If DOM API methods start with this string, we flag them as being of type 55 // If DOM API methods start with this string, we flag them as being of type
51 // DomActionType::XHR. 56 // DomActionType::XHR.
52 const char kDomXhrPrefix[] = "XMLHttpRequest."; 57 const char kDomXhrPrefix[] = "XMLHttpRequest.";
53 58
54 // Specifies a possible action to take to get an extracted URL in the ApiInfo 59 // Specifies a possible action to take to get an extracted URL in the ApiInfo
55 // structure below. 60 // structure below.
56 enum Transformation { 61 enum Transformation {
57 NONE, 62 NONE,
58 DICT_LOOKUP, 63 DICT_LOOKUP,
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 391
387 db_enabled_ = has_threads_ 392 db_enabled_ = has_threads_
388 && (CommandLine::ForCurrentProcess()-> 393 && (CommandLine::ForCurrentProcess()->
389 HasSwitch(switches::kEnableExtensionActivityLogging) 394 HasSwitch(switches::kEnableExtensionActivityLogging)
390 || watchdog_apps_active_); 395 || watchdog_apps_active_);
391 396
392 ExtensionSystem::Get(profile_)->ready().Post( 397 ExtensionSystem::Get(profile_)->ready().Post(
393 FROM_HERE, 398 FROM_HERE,
394 base::Bind(&ActivityLog::InitInstallTracker, base::Unretained(this))); 399 base::Bind(&ActivityLog::InitInstallTracker, base::Unretained(this)));
395 400
396 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
397 if (event_router)
398 event_router->SetEventDispatchObserver(this);
399
400 // None of this should run on Android since the AL is behind ENABLE_EXTENSION 401 // None of this should run on Android since the AL is behind ENABLE_EXTENSION
401 // checks. However, UmaPolicy can't even compile on Android because it uses 402 // checks. However, UmaPolicy can't even compile on Android because it uses
402 // BrowserList and related classes that aren't compiled for Android. 403 // BrowserList and related classes that aren't compiled for Android.
403 #if !defined(OS_ANDROID) 404 #if !defined(OS_ANDROID)
404 if (!profile->IsOffTheRecord()) 405 if (!profile->IsOffTheRecord())
405 uma_policy_ = new UmaPolicy(profile_); 406 uma_policy_ = new UmaPolicy(profile_);
406 #endif 407 #endif
407 408
408 ChooseDatabasePolicy(); 409 ChooseDatabasePolicy();
409 } 410 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 for (std::set<std::string>::const_iterator it2 = it->second.begin(); 611 for (std::set<std::string>::const_iterator it2 = it->second.begin();
611 it2 != it->second.end(); 612 it2 != it->second.end();
612 ++it2) { 613 ++it2) {
613 action->mutable_args()->AppendString(*it2); 614 action->mutable_args()->AppendString(*it2);
614 } 615 }
615 LogAction(action); 616 LogAction(action);
616 } 617 }
617 } 618 }
618 } 619 }
619 620
620 void ActivityLog::OnWillDispatchEvent(scoped_ptr<EventDispatchInfo> details) { 621 void ActivityLog::OnApiEventDispatched(const std::string& extension_id,
621 scoped_refptr<Action> action = new Action(details->extension_id, 622 const std::string& event_name,
623 scoped_ptr<base::ListValue> event_args) {
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
625 scoped_refptr<Action> action = new Action(extension_id,
622 base::Time::Now(), 626 base::Time::Now(),
623 Action::ACTION_API_EVENT, 627 Action::ACTION_API_EVENT,
624 details->event_name); 628 event_name);
625 action->set_args(details->event_args.Pass()); 629 action->set_args(event_args.Pass());
626 LogAction(action); 630 LogAction(action);
627 } 631 }
628 632
633 void ActivityLog::OnApiFunctionCalled(const std::string& extension_id,
634 const std::string& api_name,
635 scoped_ptr<base::ListValue> args) {
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
637 scoped_refptr<Action> action = new Action(extension_id,
638 base::Time::Now(),
639 Action::ACTION_API_CALL,
640 api_name);
641 action->set_args(args.Pass());
642 LogAction(action);
643 }
644
629 // LOOKUP ACTIONS. ------------------------------------------------------------- 645 // LOOKUP ACTIONS. -------------------------------------------------------------
630 646
631 void ActivityLog::GetFilteredActions( 647 void ActivityLog::GetFilteredActions(
632 const std::string& extension_id, 648 const std::string& extension_id,
633 const Action::ActionType type, 649 const Action::ActionType type,
634 const std::string& api_name, 650 const std::string& api_name,
635 const std::string& page_url, 651 const std::string& page_url,
636 const std::string& arg_url, 652 const std::string& arg_url,
637 const int daysAgo, 653 const int daysAgo,
638 const base::Callback 654 const base::Callback
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 RemoveURLs(urls); 687 RemoveURLs(urls);
672 } 688 }
673 689
674 void ActivityLog::DeleteDatabase() { 690 void ActivityLog::DeleteDatabase() {
675 if (!database_policy_) 691 if (!database_policy_)
676 return; 692 return;
677 database_policy_->DeleteDatabase(); 693 database_policy_->DeleteDatabase();
678 } 694 }
679 695
680 } // namespace extensions 696 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698