OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_FLASH_LSO_SETTINGS_HELPER_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_PEPPER_FLASH_LSO_SETTINGS_HELPER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" |
| 14 #include "ppapi/c/private/ppb_flash.h" |
| 15 |
| 16 class GURL; |
| 17 class Profile; |
| 18 |
| 19 namespace content { |
| 20 class ResourceContext; |
| 21 } |
| 22 |
| 23 namespace chrome { |
| 24 |
| 25 // This class aids in getting the Flash LSO Settings. |
| 26 class FlashLSOSettingsHelper |
| 27 : public base::RefCountedThreadSafe<FlashLSOSettingsHelper>, |
| 28 public content::NotificationObserver { |
| 29 public: |
| 30 explicit FlashLSOSettingsHelper(int render_process_id); |
| 31 |
| 32 // Gets the Flash local data restrictions for the given document/plugin URLs. |
| 33 // Should only be called from the IO thread. |callback| will be run with the |
| 34 // data restriction settings on the IO thread. It may be run synchronously or |
| 35 // asynchronously. |
| 36 void GetLocalDataRestrictions( |
| 37 const GURL& document_url, |
| 38 const GURL& plugin_url, |
| 39 const base::Callback<void(PP_FlashLSORestrictions)>& callback); |
| 40 |
| 41 // Unregisters profile destruction notifications and posts a task to clear |
| 42 // the resource context. This MUST be called before the last reference to the |
| 43 // object is released. |
| 44 void ShutdownOnUIThread(); |
| 45 |
| 46 private: |
| 47 virtual ~FlashLSOSettingsHelper(); |
| 48 friend class base::RefCountedThreadSafe<FlashLSOSettingsHelper>; |
| 49 |
| 50 // Runs |callback| with the local data restrictions for the given resource |
| 51 // context. The resource context is cached locally. |
| 52 void GetLocalDataRestrictionsHelper( |
| 53 const GURL& document_url, |
| 54 const GURL& plugin_url, |
| 55 const base::Callback<void(PP_FlashLSORestrictions)>& callback, |
| 56 content::ResourceContext* resource_context); |
| 57 |
| 58 // Gets the resource context for the given render process ID. The resource |
| 59 // context belongs to the Profile which lives on the UI thread so this should |
| 60 // be run on the UI thread. This also registers this class for a notification |
| 61 // on profile destruction so that the resource context is not accessed after |
| 62 // that point. |
| 63 content::ResourceContext* GetResourceContext(int render_process_id); |
| 64 |
| 65 // content::NotificationObserver implementation. |
| 66 virtual void Observe(int type, |
| 67 const content::NotificationSource& source, |
| 68 const content::NotificationDetails& details) OVERRIDE; |
| 69 |
| 70 // Clears |resource_context_| on the IO thread when the profile is destroyed. |
| 71 void ClearResourceContext(); |
| 72 |
| 73 // The render process ID of the renderer process to get LSO settings for. |
| 74 // Should only be accessed on the IO thread. |
| 75 int render_process_id_; |
| 76 |
| 77 // Whether the |resource_context_| has been initialized yet. Should only be |
| 78 // accessed from the IO thread. |
| 79 bool initialized_; |
| 80 |
| 81 // For fetching the Flash LSO settings. Should only be accessed from the IO |
| 82 // thread. |
| 83 content::ResourceContext* resource_context_; |
| 84 |
| 85 // Registrar for receiving profile destruction notifications. Should only be |
| 86 // accessed from the UI thread. |
| 87 scoped_ptr<content::NotificationRegistrar> registrar_; |
| 88 |
| 89 // Whether the object has been shutdown. Should only be accessed from the UI |
| 90 // thread (except in the destructor because this should be set to true before |
| 91 // destruction). This is used for checking only. |
| 92 bool is_shutdown_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(FlashLSOSettingsHelper); |
| 95 }; |
| 96 |
| 97 } // namespace chrome |
| 98 |
| 99 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_FLASH_LSO_SETTINGS_HELPER_H_ |
OLD | NEW |