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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_COMMON_NET_URL_REQUEST_CONTEXT_GETTER_H_ 6 #define CHROME_COMMON_NET_URL_REQUEST_CONTEXT_GETTER_H_ 7 #pragma once 8 9 #include "base/memory/ref_counted.h" 10 #include "base/task.h" 11 12 namespace base { 13 class MessageLoopProxy; 14 } 15 16 namespace net { 17 class CookieStore; 18 class URLRequestContext; 19 20 struct URLRequestContextGetterTraits; 21 22 // Interface for retrieving an net::URLRequestContext. 23 class URLRequestContextGetter 24 : public base::RefCountedThreadSafe<URLRequestContextGetter, 25 URLRequestContextGetterTraits> { 26 public: 27 virtual URLRequestContext* GetURLRequestContext() = 0; 28 29 // See http://crbug.com/77835 for why this shouldn't be used. Instead use 30 // GetURLRequestContext()->cookie_store(); 31 virtual CookieStore* DONTUSEME_GetCookieStore(); 32 33 // Returns a MessageLoopProxy corresponding to the thread on which the 34 // request IO happens (the thread on which the returned net::URLRequestContext 35 // may be used). 36 virtual scoped_refptr<base::MessageLoopProxy> 37 GetIOMessageLoopProxy() const = 0; 38 39 // Controls whether or not the URLRequestContextGetter considers itself to be 40 // the the "main" URLRequestContextGetter. Note that each Profile will have a 41 // "default" URLRequestContextGetter. Therefore, "is_main" refers to the 42 // default URLRequestContextGetter for the "main" Profile. 43 // TODO(willchan): Move this code to ChromeURLRequestContextGetter, since this 44 // ia a browser process specific concept. 45 void set_is_main(bool is_main) { is_main_ = is_main; } 46 47 protected: 48 friend class DeleteTask<const URLRequestContextGetter>; 49 friend struct URLRequestContextGetterTraits; 50 51 URLRequestContextGetter(); 52 virtual ~URLRequestContextGetter(); 53 54 bool is_main() const { return is_main_; } 55 56 private: 57 // OnDestruct is meant to ensure deletion on the thread on which the request 58 // IO happens. 59 void OnDestruct() const; 60 61 // Indicates whether or not this is the default URLRequestContextGetter for 62 // the main Profile. 63 bool is_main_; 64 }; 65 66 struct URLRequestContextGetterTraits { 67 static void Destruct(const URLRequestContextGetter* context_getter) { 68 context_getter->OnDestruct(); 69 } 70 }; 71 72 } // namespace net 73 74 #endif // CHROME_COMMON_NET_URL_REQUEST_CONTEXT_GETTER_H_ 75