| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains an implementation of the ResourceLoaderBridge class. | 5 // This file contains an implementation of the ResourceLoaderBridge class. |
| 6 // The class is implemented using net::URLRequest, meaning it is a "simple" | 6 // The class is implemented using net::URLRequest, meaning it is a "simple" |
| 7 // version that directly issues requests. The more complicated one used in the | 7 // version that directly issues requests. The more complicated one used in the |
| 8 // browser uses IPC. | 8 // browser uses IPC. |
| 9 // | 9 // |
| 10 // Because net::URLRequest only provides an asynchronous resource loading API, | 10 // Because net::URLRequest only provides an asynchronous resource loading API, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // -> net_util::GetCookies | 25 // -> net_util::GetCookies |
| 26 // | 26 // |
| 27 // NOTE: The implementation in this file may be used to have WebKit fetch | 27 // NOTE: The implementation in this file may be used to have WebKit fetch |
| 28 // resources in-process. For example, it is handy for building a single- | 28 // resources in-process. For example, it is handy for building a single- |
| 29 // process WebKit embedding (e.g., test_shell) that can use net::URLRequest to | 29 // process WebKit embedding (e.g., test_shell) that can use net::URLRequest to |
| 30 // perform URL loads. See renderer/resource_dispatcher.h for details on an | 30 // perform URL loads. See renderer/resource_dispatcher.h for details on an |
| 31 // alternate implementation that defers fetching to another process. | 31 // alternate implementation that defers fetching to another process. |
| 32 | 32 |
| 33 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 33 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 34 | 34 |
| 35 #include "base/bind.h" |
| 35 #include "base/compiler_specific.h" | 36 #include "base/compiler_specific.h" |
| 36 #include "base/file_path.h" | 37 #include "base/file_path.h" |
| 37 #include "base/file_util.h" | 38 #include "base/file_util.h" |
| 38 #include "base/logging.h" | 39 #include "base/logging.h" |
| 39 #include "base/message_loop.h" | 40 #include "base/message_loop.h" |
| 40 #include "base/message_loop_proxy.h" | 41 #include "base/message_loop_proxy.h" |
| 41 #include "base/memory/ref_counted.h" | 42 #include "base/memory/ref_counted.h" |
| 42 #include "base/time.h" | 43 #include "base/time.h" |
| 43 #include "base/timer.h" | 44 #include "base/timer.h" |
| 44 #include "base/threading/thread.h" | 45 #include "base/threading/thread.h" |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 // sticks around until this ResourceLoaderBridge is destroyed. | 739 // sticks around until this ResourceLoaderBridge is destroyed. |
| 739 RequestProxy* proxy_; | 740 RequestProxy* proxy_; |
| 740 }; | 741 }; |
| 741 | 742 |
| 742 //----------------------------------------------------------------------------- | 743 //----------------------------------------------------------------------------- |
| 743 | 744 |
| 744 class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> { | 745 class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> { |
| 745 public: | 746 public: |
| 746 void Set(const GURL& url, const std::string& cookie) { | 747 void Set(const GURL& url, const std::string& cookie) { |
| 747 DCHECK(MessageLoop::current() == g_io_thread->message_loop()); | 748 DCHECK(MessageLoop::current() == g_io_thread->message_loop()); |
| 748 g_request_context->cookie_store()->SetCookie(url, cookie); | 749 g_request_context->cookie_store()->SetCookieWithOptionsAsync( |
| 750 url, cookie, net::CookieOptions(), |
| 751 net::CookieStore::SetCookiesCallback()); |
| 749 } | 752 } |
| 750 | 753 |
| 751 private: | 754 private: |
| 755 |
| 752 friend class base::RefCountedThreadSafe<CookieSetter>; | 756 friend class base::RefCountedThreadSafe<CookieSetter>; |
| 753 | 757 |
| 754 ~CookieSetter() {} | 758 ~CookieSetter() {} |
| 755 }; | 759 }; |
| 756 | 760 |
| 757 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> { | 761 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> { |
| 758 public: | 762 public: |
| 759 CookieGetter() : event_(false, false) { | 763 CookieGetter() : event_(false, false) { |
| 760 } | 764 } |
| 761 | 765 |
| 762 void Get(const GURL& url) { | 766 void Get(const GURL& url) { |
| 763 result_ = g_request_context->cookie_store()->GetCookies(url); | 767 g_request_context->cookie_store()->GetCookiesWithOptionsAsync( |
| 764 event_.Signal(); | 768 url, net::CookieOptions(), |
| 769 base::Bind(&CookieGetter::OnGetCookies, this)); |
| 765 } | 770 } |
| 766 | 771 |
| 767 std::string GetResult() { | 772 std::string GetResult() { |
| 768 if (!event_.Wait()) | 773 if (!event_.Wait()) |
| 769 NOTREACHED(); | 774 NOTREACHED(); |
| 770 return result_; | 775 return result_; |
| 771 } | 776 } |
| 772 | 777 |
| 773 private: | 778 private: |
| 779 void OnGetCookies(const std::string& cookie_line) { |
| 780 result_ = cookie_line; |
| 781 event_.Signal(); |
| 782 } |
| 774 friend class base::RefCountedThreadSafe<CookieGetter>; | 783 friend class base::RefCountedThreadSafe<CookieGetter>; |
| 775 | 784 |
| 776 ~CookieGetter() {} | 785 ~CookieGetter() {} |
| 777 | 786 |
| 778 base::WaitableEvent event_; | 787 base::WaitableEvent event_; |
| 779 std::string result_; | 788 std::string result_; |
| 780 }; | 789 }; |
| 781 | 790 |
| 782 } // anonymous namespace | 791 } // anonymous namespace |
| 783 | 792 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 908 |
| 900 // static | 909 // static |
| 901 scoped_refptr<base::MessageLoopProxy> | 910 scoped_refptr<base::MessageLoopProxy> |
| 902 SimpleResourceLoaderBridge::GetIoThread() { | 911 SimpleResourceLoaderBridge::GetIoThread() { |
| 903 if (!EnsureIOThread()) { | 912 if (!EnsureIOThread()) { |
| 904 LOG(DFATAL) << "Failed to create IO thread."; | 913 LOG(DFATAL) << "Failed to create IO thread."; |
| 905 return NULL; | 914 return NULL; |
| 906 } | 915 } |
| 907 return g_io_thread->message_loop_proxy(); | 916 return g_io_thread->message_loop_proxy(); |
| 908 } | 917 } |
| OLD | NEW |