summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/chrome_url_request_context.h
blob: f9cfafacddd884386fd0e7b6930e2a05718a1672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2006-2008 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/file_path.h"
#include "chrome/common/net/cookie_monster_sqlite.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_service.h"
#include "net/url_request/url_request_context.h"

class Profile;

// A URLRequestContext subclass used by the browser. This can be used to store
// extra information about requests, beyond what is supported by the base
// URLRequestContext class.
//
// All methods are expected to be called on the IO thread except the
// constructor and factories (CreateOriginal, CreateOffTheRecord), which are
// expected to be called on the UI thread.
class ChromeURLRequestContext : public URLRequestContext,
                                public NotificationObserver {
 public:
  typedef std::map<std::string, FilePath> ExtensionPaths;

  // Create an instance for use with an 'original' (non-OTR) profile. This is
  // expected to get called on the UI thread.
  static ChromeURLRequestContext* CreateOriginal(
      Profile* profile, const FilePath& cookie_store_path,
      const FilePath& disk_cache_path);

  // Create an instance for use with an OTR profile. This is expected to get
  // called on the UI thread.
  static ChromeURLRequestContext* CreateOffTheRecord(Profile* profile);

  // Clean up UI thread resources. This is expected to get called on the UI
  // thread before the instance is deleted on the IO thread.
  void CleanupOnUIThread();

  // Gets the path to the directory for the specified extension.
  FilePath GetPathForExtension(const std::string& id);

  // Gets the path to the directory user scripts are stored in.
  FilePath user_script_dir_path() const {
    return user_script_dir_path_;
  }

  virtual const std::string& GetUserAgent(const GURL& url) const;

 private:
  // Private constructor, use the static factory methods instead. This is
  // expected to be called on the UI thread.
  ChromeURLRequestContext(Profile* profile);

  // NotificationObserver implementation.
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // Callback for when the accept language changes.
  void OnAcceptLanguageChange(std::string accept_language);

  // Callback for when the cookie policy changes.
  void OnCookiePolicyChange(net::CookiePolicy::Type type);

  // Callback for when new extensions are loaded.
  void OnNewExtensions(ExtensionPaths* new_paths);

  // Destructor.
  virtual ~ChromeURLRequestContext();

  // Maps extension IDs to paths on disk. This is initialized in the
  // construtor and updated when extensions changed.
  ExtensionPaths extension_paths_;

  // Path to the directory user scripts are stored in.
  FilePath user_script_dir_path_;

  scoped_ptr<SQLitePersistentCookieStore> cookie_db_;
  PrefService* prefs_;
  bool is_off_the_record_;
};