| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "chrome/browser/history/history_types.h" | 36 #include "chrome/browser/history/history_types.h" |
| 37 #include "chrome/browser/history/top_sites.h" | 37 #include "chrome/browser/history/top_sites.h" |
| 38 #include "chrome/browser/infobars/infobar_tab_helper.h" | 38 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 39 #include "chrome/browser/metrics/metric_event_duration_details.h" | 39 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 40 #include "chrome/browser/notifications/balloon.h" | 40 #include "chrome/browser/notifications/balloon.h" |
| 41 #include "chrome/browser/notifications/balloon_collection.h" | 41 #include "chrome/browser/notifications/balloon_collection.h" |
| 42 #include "chrome/browser/notifications/balloon_host.h" | 42 #include "chrome/browser/notifications/balloon_host.h" |
| 43 #include "chrome/browser/notifications/notification.h" | 43 #include "chrome/browser/notifications/notification.h" |
| 44 #include "chrome/browser/notifications/notification_ui_manager.h" | 44 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 45 #include "chrome/browser/password_manager/password_store_change.h" | 45 #include "chrome/browser/password_manager/password_store_change.h" |
| 46 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 47 #include "chrome/browser/profiles/profile.h" | 46 #include "chrome/browser/profiles/profile.h" |
| 48 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 47 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 49 #include "chrome/browser/search_engines/template_url_service.h" | 48 #include "chrome/browser/search_engines/template_url_service.h" |
| 50 #include "chrome/browser/search_engines/template_url_service_factory.h" | 49 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 51 #include "chrome/browser/sessions/restore_tab_helper.h" | 50 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 52 #include "chrome/browser/sessions/tab_restore_service.h" | 51 #include "chrome/browser/sessions/tab_restore_service.h" |
| 53 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 52 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 54 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 53 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 55 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 54 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 56 #include "chrome/browser/translate/page_translated_details.h" | 55 #include "chrome/browser/translate/page_translated_details.h" |
| (...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 AutomationJSONReply(automation_, reply_message_.release()) | 2939 AutomationJSONReply(automation_, reply_message_.release()) |
| 2941 .SendSuccess(NULL); | 2940 .SendSuccess(NULL); |
| 2942 } | 2941 } |
| 2943 delete this; | 2942 delete this; |
| 2944 } | 2943 } |
| 2945 } else { | 2944 } else { |
| 2946 NOTREACHED(); | 2945 NOTREACHED(); |
| 2947 } | 2946 } |
| 2948 } | 2947 } |
| 2949 | 2948 |
| 2950 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 2951 | |
| 2952 PolicyUpdatesObserver::PolicyUpdatesObserver( | |
| 2953 AutomationProvider* automation, | |
| 2954 IPC::Message* reply_message, | |
| 2955 policy::BrowserPolicyConnector* browser_policy_connector) | |
| 2956 : automation_(automation->AsWeakPtr()), | |
| 2957 reply_message_(reply_message) { | |
| 2958 policy::ConfigurationPolicyProvider* providers[] = { | |
| 2959 browser_policy_connector->GetManagedCloudProvider(), | |
| 2960 browser_policy_connector->GetManagedPlatformProvider(), | |
| 2961 browser_policy_connector->GetRecommendedCloudProvider(), | |
| 2962 browser_policy_connector->GetRecommendedPlatformProvider(), | |
| 2963 }; | |
| 2964 for (size_t i = 0; i < arraysize(providers); ++i) { | |
| 2965 if (providers[i]) { | |
| 2966 registrars_.push_back(new policy::ConfigurationPolicyObserverRegistrar); | |
| 2967 registrars_.back()->Init(providers[i], this); | |
| 2968 } | |
| 2969 } | |
| 2970 MaybeReply(); | |
| 2971 } | |
| 2972 | |
| 2973 PolicyUpdatesObserver::~PolicyUpdatesObserver() {} | |
| 2974 | |
| 2975 // static | |
| 2976 void PolicyUpdatesObserver::PostCallbackAfterPolicyUpdates( | |
| 2977 const base::Closure& callback) { | |
| 2978 // Some policies (e.g. URLBlacklist) post tasks to other message loops before | |
| 2979 // they start enforcing updated policy values; make sure those tasks have | |
| 2980 // finished after a policy update. | |
| 2981 // Updates of the URLBlacklist are done on IO, after building the blacklist | |
| 2982 // on FILE, which is initiated from IO. | |
| 2983 PostTask(BrowserThread::IO, | |
| 2984 base::Bind(&PostTask, BrowserThread::FILE, | |
| 2985 base::Bind(&PostTask, BrowserThread::IO, | |
| 2986 base::Bind(&PostTask, BrowserThread::UI, callback)))); | |
| 2987 } | |
| 2988 | |
| 2989 void PolicyUpdatesObserver::OnUpdatePolicy( | |
| 2990 policy::ConfigurationPolicyProvider* provider) { | |
| 2991 std::vector<policy::ConfigurationPolicyObserverRegistrar*>::iterator it; | |
| 2992 for (it = registrars_.begin(); it != registrars_.end(); ++it) { | |
| 2993 if ((*it)->provider() == provider) { | |
| 2994 delete *it; | |
| 2995 registrars_.erase(it); | |
| 2996 MaybeReply(); | |
| 2997 return; | |
| 2998 } | |
| 2999 } | |
| 3000 } | |
| 3001 | |
| 3002 void PolicyUpdatesObserver::OnProviderGoingAway( | |
| 3003 policy::ConfigurationPolicyProvider* provider) { | |
| 3004 STLDeleteElements(®istrars_); | |
| 3005 if (automation_) { | |
| 3006 AutomationJSONReply(automation_, reply_message_.release()).SendError( | |
| 3007 "Policy provider went away."); | |
| 3008 } | |
| 3009 delete this; | |
| 3010 } | |
| 3011 | |
| 3012 void PolicyUpdatesObserver::MaybeReply() { | |
| 3013 if (registrars_.empty()) { | |
| 3014 PostCallbackAfterPolicyUpdates( | |
| 3015 base::Bind(&PolicyUpdatesObserver::Reply, base::Owned(this))); | |
| 3016 } | |
| 3017 } | |
| 3018 | |
| 3019 void PolicyUpdatesObserver::Reply() { | |
| 3020 if (automation_) { | |
| 3021 AutomationJSONReply( | |
| 3022 automation_, reply_message_.release()).SendSuccess(NULL); | |
| 3023 } | |
| 3024 // Reply() is only called from MaybeReply(), which makes the callback own | |
| 3025 // |this|; so |this| will be deleted once this method returns. | |
| 3026 } | |
| 3027 | |
| 3028 // static | |
| 3029 void PolicyUpdatesObserver::PostTask(content::BrowserThread::ID id, | |
| 3030 const base::Closure& callback) { | |
| 3031 content::BrowserThread::PostTask(id, FROM_HERE, callback); | |
| 3032 } | |
| 3033 | |
| 3034 #endif // defined(ENABLE_CONFIGURATION_POLICY) | |
| 3035 | |
| 3036 ExtensionPopupObserver::ExtensionPopupObserver( | 2949 ExtensionPopupObserver::ExtensionPopupObserver( |
| 3037 AutomationProvider* automation, | 2950 AutomationProvider* automation, |
| 3038 IPC::Message* reply_message, | 2951 IPC::Message* reply_message, |
| 3039 const std::string& extension_id) | 2952 const std::string& extension_id) |
| 3040 : automation_(automation->AsWeakPtr()), | 2953 : automation_(automation->AsWeakPtr()), |
| 3041 reply_message_(reply_message), | 2954 reply_message_(reply_message), |
| 3042 extension_id_(extension_id) { | 2955 extension_id_(extension_id) { |
| 3043 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 2956 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 3044 content::NotificationService::AllSources()); | 2957 content::NotificationService::AllSources()); |
| 3045 } | 2958 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3057 } | 2970 } |
| 3058 | 2971 |
| 3059 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 2972 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 3060 if (host->extension_id() == extension_id_ && | 2973 if (host->extension_id() == extension_id_ && |
| 3061 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 2974 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 3062 AutomationJSONReply(automation_, reply_message_.release()) | 2975 AutomationJSONReply(automation_, reply_message_.release()) |
| 3063 .SendSuccess(NULL); | 2976 .SendSuccess(NULL); |
| 3064 delete this; | 2977 delete this; |
| 3065 } | 2978 } |
| 3066 } | 2979 } |
| OLD | NEW |