Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1076)

Unified Diff: net/proxy/proxy_resolver_error_observer_mojo.cc

Issue 1017453005: Add support for ProxyResolverErrorObserver to ProxyResolverMojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/proxy/proxy_resolver_error_observer_mojo.cc
diff --git a/net/proxy/proxy_resolver_error_observer_mojo.cc b/net/proxy/proxy_resolver_error_observer_mojo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..89d472bc69008321bbe4c1d82cf05410d5416cc7
--- /dev/null
+++ b/net/proxy/proxy_resolver_error_observer_mojo.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 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 "net/proxy/proxy_resolver_error_observer_mojo.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_checker.h"
+#include "mojo/common/common_type_converters.h"
+
+namespace net {
+
+class ProxyResolverErrorObserverMojo::Core
Anand Mistry (off Chromium) 2015/03/20 03:12:32 I think you can simplify this code and eliminate t
Sam McNally 2015/03/20 03:52:41 Done.
+ : public base::RefCountedThreadSafe<ProxyResolverErrorObserverMojo::Core> {
+ public:
+ explicit Core(interfaces::ProxyResolverErrorObserverPtr error_observer);
+ void SendOnPacScriptError(int line_number, const base::string16& error);
+
+ private:
+ friend class base::RefCountedThreadSafe<Core>;
+
+ ~Core();
+
+ interfaces::ProxyResolverErrorObserverPtr error_observer_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ base::ThreadChecker thread_checker_;
+};
+
+// static
+scoped_ptr<ProxyResolverErrorObserver> ProxyResolverErrorObserverMojo::Create(
+ interfaces::ProxyResolverErrorObserverPtr error_observer) {
+ if (!error_observer)
+ return nullptr;
+
+ return scoped_ptr<ProxyResolverErrorObserver>(
+ new ProxyResolverErrorObserverMojo(error_observer.Pass()));
+}
+
+void ProxyResolverErrorObserverMojo::OnPACScriptError(
+ int line_number,
+ const base::string16& error) {
+ core_->SendOnPacScriptError(line_number, error);
+}
+
+ProxyResolverErrorObserverMojo::ProxyResolverErrorObserverMojo(
+ interfaces::ProxyResolverErrorObserverPtr error_observer)
+ : core_(new Core(error_observer.Pass())) {
+}
+
+ProxyResolverErrorObserverMojo::~ProxyResolverErrorObserverMojo() = default;
+
+ProxyResolverErrorObserverMojo::Core::Core(
+ interfaces::ProxyResolverErrorObserverPtr error_observer)
+ : error_observer_(error_observer.Pass()),
+ task_runner_(base::MessageLoopProxy::current()) {
+}
+
+void ProxyResolverErrorObserverMojo::Core::SendOnPacScriptError(
+ int line_number,
+ const base::string16& error) {
+ if (!task_runner_->RunsTasksOnCurrentThread()) {
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&ProxyResolverErrorObserverMojo::Core::SendOnPacScriptError,
+ this, line_number, error));
+ return;
+ }
+ DCHECK(thread_checker_.CalledOnValidThread());
+ error_observer_->OnPacScriptError(line_number, mojo::String::From(error));
+}
+
+ProxyResolverErrorObserverMojo::Core::~Core() = default;
+
+} // namespace net
« no previous file with comments | « net/proxy/proxy_resolver_error_observer_mojo.h ('k') | net/proxy/proxy_resolver_error_observer_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698