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_UI_WEBUI_MEDIA_MEDIA_INTERNALS_PROXY_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_MEDIA_INTERNALS_PROXY_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/sequenced_task_runner_helpers.h" | |
10 #include "base/string16.h" | |
11 #include "chrome/browser/media/media_internals_observer.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/notification_observer.h" | |
14 #include "content/public/browser/notification_registrar.h" | |
15 #include "net/base/net_log.h" | |
16 | |
17 class IOThread; | |
18 class MediaInternalsMessageHandler; | |
19 | |
20 namespace base { | |
21 class ListValue; | |
22 class Value; | |
23 } | |
24 | |
25 // This class is a proxy between MediaInternals (on the IO thread) and | |
26 // MediaInternalsMessageHandler (on the UI thread). | |
27 // It is ref_counted to ensure that it completes all pending Tasks on both | |
28 // threads before destruction. | |
29 class MediaInternalsProxy | |
30 : public MediaInternalsObserver, | |
31 public base::RefCountedThreadSafe< | |
32 MediaInternalsProxy, | |
33 content::BrowserThread::DeleteOnUIThread>, | |
34 public net::NetLog::ThreadSafeObserver, | |
35 public content::NotificationObserver { | |
36 public: | |
37 MediaInternalsProxy(); | |
38 | |
39 // content::NotificationObserver implementation. | |
40 virtual void Observe(int type, | |
41 const content::NotificationSource& source, | |
42 const content::NotificationDetails& details) OVERRIDE; | |
43 | |
44 // Register a Handler and start receiving callbacks from MediaInternals. | |
45 void Attach(MediaInternalsMessageHandler* handler); | |
46 | |
47 // Unregister the same and stop receiving callbacks. | |
48 void Detach(); | |
49 | |
50 // Have MediaInternals send all the data it has. | |
51 void GetEverything(); | |
52 | |
53 // MediaInternalsObserver implementation. Called on the IO thread. | |
54 virtual void OnUpdate(const string16& update) OVERRIDE; | |
55 | |
56 // net::NetLog::ThreadSafeObserver implementation. Callable from any thread: | |
57 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | |
58 | |
59 private: | |
60 friend struct content::BrowserThread::DeleteOnThread< | |
61 content::BrowserThread::UI>; | |
62 friend class base::DeleteHelper<MediaInternalsProxy>; | |
63 virtual ~MediaInternalsProxy(); | |
64 | |
65 // Build a dictionary mapping constant names to values. | |
66 base::Value* GetConstants(); | |
67 | |
68 void ObserveMediaInternalsOnIOThread(); | |
69 void StopObservingMediaInternalsOnIOThread(); | |
70 void GetEverythingOnIOThread(); | |
71 void UpdateUIOnUIThread(const string16& update); | |
72 | |
73 // Put |entry| on a list of events to be sent to the page. | |
74 void AddNetEventOnUIThread(base::Value* entry); | |
75 | |
76 // Send all pending events to the page. | |
77 void SendNetEventsOnUIThread(); | |
78 | |
79 // Call a JavaScript function on the page. Takes ownership of |args|. | |
80 void CallJavaScriptFunctionOnUIThread(const std::string& function, | |
81 base::Value* args); | |
82 | |
83 MediaInternalsMessageHandler* handler_; | |
84 IOThread* io_thread_; | |
85 scoped_ptr<base::ListValue> pending_net_updates_; | |
86 content::NotificationRegistrar registrar_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(MediaInternalsProxy); | |
89 }; | |
90 | |
91 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_MEDIA_INTERNALS_PROXY_H_ | |
OLD | NEW |