| 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 2881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2938 AutomationJSONReply(automation_, reply_message_.release()) | 2937 AutomationJSONReply(automation_, reply_message_.release()) |
| 2939 .SendSuccess(NULL); | 2938 .SendSuccess(NULL); |
| 2940 } | 2939 } |
| 2941 delete this; | 2940 delete this; |
| 2942 } | 2941 } |
| 2943 } else { | 2942 } else { |
| 2944 NOTREACHED(); | 2943 NOTREACHED(); |
| 2945 } | 2944 } |
| 2946 } | 2945 } |
| 2947 | 2946 |
| 2948 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 2949 | |
| 2950 PolicyUpdatesObserver::PolicyUpdatesObserver( | |
| 2951 AutomationProvider* automation, | |
| 2952 IPC::Message* reply_message, | |
| 2953 policy::BrowserPolicyConnector* browser_policy_connector) | |
| 2954 : automation_(automation->AsWeakPtr()), | |
| 2955 reply_message_(reply_message) { | |
| 2956 policy::ConfigurationPolicyProvider* providers[] = { | |
| 2957 browser_policy_connector->GetManagedCloudProvider(), | |
| 2958 browser_policy_connector->GetManagedPlatformProvider(), | |
| 2959 browser_policy_connector->GetRecommendedCloudProvider(), | |
| 2960 browser_policy_connector->GetRecommendedPlatformProvider(), | |
| 2961 }; | |
| 2962 for (size_t i = 0; i < arraysize(providers); ++i) { | |
| 2963 if (providers[i]) { | |
| 2964 registrars_.push_back(new policy::ConfigurationPolicyObserverRegistrar); | |
| 2965 registrars_.back()->Init(providers[i], this); | |
| 2966 } | |
| 2967 } | |
| 2968 MaybeReply(); | |
| 2969 } | |
| 2970 | |
| 2971 PolicyUpdatesObserver::~PolicyUpdatesObserver() {} | |
| 2972 | |
| 2973 // static | |
| 2974 void PolicyUpdatesObserver::PostCallbackAfterPolicyUpdates( | |
| 2975 const base::Closure& callback) { | |
| 2976 // Some policies (e.g. URLBlacklist) post tasks to other message loops before | |
| 2977 // they start enforcing updated policy values; make sure those tasks have | |
| 2978 // finished after a policy update. | |
| 2979 // Updates of the URLBlacklist are done on IO, after building the blacklist | |
| 2980 // on FILE, which is initiated from IO. | |
| 2981 PostTask(BrowserThread::IO, | |
| 2982 base::Bind(&PostTask, BrowserThread::FILE, | |
| 2983 base::Bind(&PostTask, BrowserThread::IO, | |
| 2984 base::Bind(&PostTask, BrowserThread::UI, callback)))); | |
| 2985 } | |
| 2986 | |
| 2987 void PolicyUpdatesObserver::OnUpdatePolicy( | |
| 2988 policy::ConfigurationPolicyProvider* provider) { | |
| 2989 std::vector<policy::ConfigurationPolicyObserverRegistrar*>::iterator it; | |
| 2990 for (it = registrars_.begin(); it != registrars_.end(); ++it) { | |
| 2991 if ((*it)->provider() == provider) { | |
| 2992 delete *it; | |
| 2993 registrars_.erase(it); | |
| 2994 MaybeReply(); | |
| 2995 return; | |
| 2996 } | |
| 2997 } | |
| 2998 } | |
| 2999 | |
| 3000 void PolicyUpdatesObserver::OnProviderGoingAway( | |
| 3001 policy::ConfigurationPolicyProvider* provider) { | |
| 3002 STLDeleteElements(®istrars_); | |
| 3003 if (automation_) { | |
| 3004 AutomationJSONReply(automation_, reply_message_.release()).SendError( | |
| 3005 "Policy provider went away."); | |
| 3006 } | |
| 3007 delete this; | |
| 3008 } | |
| 3009 | |
| 3010 void PolicyUpdatesObserver::MaybeReply() { | |
| 3011 if (registrars_.empty()) { | |
| 3012 PostCallbackAfterPolicyUpdates( | |
| 3013 base::Bind(&PolicyUpdatesObserver::Reply, base::Owned(this))); | |
| 3014 } | |
| 3015 } | |
| 3016 | |
| 3017 void PolicyUpdatesObserver::Reply() { | |
| 3018 if (automation_) { | |
| 3019 AutomationJSONReply( | |
| 3020 automation_, reply_message_.release()).SendSuccess(NULL); | |
| 3021 } | |
| 3022 // Reply() is only called from MaybeReply(), which makes the callback own | |
| 3023 // |this|; so |this| will be deleted once this method returns. | |
| 3024 } | |
| 3025 | |
| 3026 // static | |
| 3027 void PolicyUpdatesObserver::PostTask(content::BrowserThread::ID id, | |
| 3028 const base::Closure& callback) { | |
| 3029 content::BrowserThread::PostTask(id, FROM_HERE, callback); | |
| 3030 } | |
| 3031 | |
| 3032 #endif // defined(ENABLE_CONFIGURATION_POLICY) | |
| 3033 | |
| 3034 ExtensionPopupObserver::ExtensionPopupObserver( | 2947 ExtensionPopupObserver::ExtensionPopupObserver( |
| 3035 AutomationProvider* automation, | 2948 AutomationProvider* automation, |
| 3036 IPC::Message* reply_message, | 2949 IPC::Message* reply_message, |
| 3037 const std::string& extension_id) | 2950 const std::string& extension_id) |
| 3038 : automation_(automation->AsWeakPtr()), | 2951 : automation_(automation->AsWeakPtr()), |
| 3039 reply_message_(reply_message), | 2952 reply_message_(reply_message), |
| 3040 extension_id_(extension_id) { | 2953 extension_id_(extension_id) { |
| 3041 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 2954 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 3042 content::NotificationService::AllSources()); | 2955 content::NotificationService::AllSources()); |
| 3043 } | 2956 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3055 } | 2968 } |
| 3056 | 2969 |
| 3057 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 2970 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 3058 if (host->extension_id() == extension_id_ && | 2971 if (host->extension_id() == extension_id_ && |
| 3059 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 2972 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 3060 AutomationJSONReply(automation_, reply_message_.release()) | 2973 AutomationJSONReply(automation_, reply_message_.release()) |
| 3061 .SendSuccess(NULL); | 2974 .SendSuccess(NULL); |
| 3062 delete this; | 2975 delete this; |
| 3063 } | 2976 } |
| 3064 } | 2977 } |
| OLD | NEW |