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