blob: c2672f09d45c52b5d89058f2a266972c89ea3296 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner_helpers.h"
#include "content/browser/media/media_internals.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "net/base/net_log.h"
namespace base {
class ListValue;
class Value;
namespace content {
class MediaInternalsMessageHandler;
// This class is a proxy between MediaInternals (on the IO thread) and
// MediaInternalsMessageHandler (on the UI thread).
// It is ref_counted to ensure that it completes all pending Tasks on both
// threads before destruction.
class MediaInternalsProxy
: public base::RefCountedThreadSafe<
public net::NetLog::ThreadSafeObserver,
public NotificationObserver {
// NotificationObserver implementation.
void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) override;
// Register a Handler and start receiving callbacks from MediaInternals.
void Attach(MediaInternalsMessageHandler* handler);
// Unregister the same and stop receiving callbacks.
void Detach();
// Have MediaInternals send all the data it has.
void GetEverything();
// MediaInternals callback. Called on the IO thread.
void OnUpdate(const base::string16& update);
// net::NetLog::ThreadSafeObserver implementation. Callable from any thread:
void OnAddEntry(const net::NetLog::Entry& entry) override;
friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
friend class base::DeleteHelper<MediaInternalsProxy>;
~MediaInternalsProxy() override;
// Build a dictionary mapping constant names to values.
base::Value* GetConstants();
void ObserveMediaInternalsOnIOThread();
void StopObservingMediaInternalsOnIOThread();
void GetEverythingOnIOThread();
void UpdateUIOnUIThread(const base::string16& update);
// Put |entry| on a list of events to be sent to the page.
void AddNetEventOnUIThread(base::Value* entry);
// Send all pending events to the page.
void SendNetEventsOnUIThread();
// Call a JavaScript function on the page. Takes ownership of |args|.
void CallJavaScriptFunctionOnUIThread(const std::string& function,
base::Value* args);
MediaInternalsMessageHandler* handler_;
scoped_ptr<base::ListValue> pending_net_updates_;
NotificationRegistrar registrar_;
MediaInternals::UpdateCallback update_callback_;
} // namespace content