summaryrefslogtreecommitdiff
path: root/chromium/weblayer/browser/browser_context_impl.h
blob: 7d888462025adcbc528cc8d7c0717904487d1d45 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2019 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.

#ifndef WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_

#include "base/files/file_path.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "weblayer/browser/download_manager_delegate_impl.h"
#include "weblayer/public/profile.h"

namespace user_prefs {
class PrefRegistrySyncable;
}
class PrefService;

namespace weblayer {
class ProfileImpl;
class ResourceContextImpl;

namespace prefs {
// WebLayer specific pref names.
extern const char kUkmEnabled[];
}  // namespace prefs

class BrowserContextImpl : public content::BrowserContext {
 public:
  BrowserContextImpl(ProfileImpl* profile_impl, const base::FilePath& path);
  ~BrowserContextImpl() override;
  BrowserContextImpl(const BrowserContextImpl&) = delete;
  BrowserContextImpl& operator=(const BrowserContextImpl&) = delete;

  static base::FilePath GetDefaultDownloadDirectory();

  // BrowserContext implementation:
#if !defined(OS_ANDROID)
  std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
      const base::FilePath&) override;
#endif  // !defined(OS_ANDROID)
  base::FilePath GetPath() override;
  bool IsOffTheRecord() override;
  variations::VariationsClient* GetVariationsClient() override;
  content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;

  content::ResourceContext* GetResourceContext() override;
  content::BrowserPluginGuestManager* GetGuestManager() override;
  storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
  content::PushMessagingService* GetPushMessagingService() override;
  content::StorageNotificationService* GetStorageNotificationService() override;
  content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
  content::PermissionControllerDelegate* GetPermissionControllerDelegate()
      override;
  content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
      override;
  content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
  content::BackgroundSyncController* GetBackgroundSyncController() override;
  content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
      override;
  download::InProgressDownloadManager* RetriveInProgressDownloadManager()
      override;
  content::ContentIndexProvider* GetContentIndexProvider() override;

  ProfileImpl* profile_impl() const { return profile_impl_; }

  PrefService* pref_service() const { return user_pref_service_.get(); }

 private:
  class WebLayerVariationsClient;

  // Creates a simple in-memory pref service.
  // TODO(timvolodine): Investigate whether WebLayer needs persistent pref
  // service.
  void CreateUserPrefService();

  // Registers the preferences that WebLayer accesses.
  void RegisterPrefs(user_prefs::PrefRegistrySyncable* pref_registry);

  ProfileImpl* const profile_impl_;
  base::FilePath path_;
  // ResourceContext needs to be deleted on the IO thread in general (and in
  // particular due to the destruction of the safebrowsing mojo interface
  // that has been added in ContentBrowserClient::ExposeInterfacesToRenderer
  // on IO thread, see crbug.com/1029317). Also this is similar to how Chrome
  // handles ProfileIOData.
  // TODO(timvolodine): consider a more general Profile shutdown/destruction
  // sequence for the IO/UI bits (crbug.com/1029879).
  std::unique_ptr<ResourceContextImpl, content::BrowserThread::DeleteOnIOThread>
      resource_context_;
  DownloadManagerDelegateImpl download_delegate_;
  std::unique_ptr<PrefService> user_pref_service_;
  std::unique_ptr<WebLayerVariationsClient> weblayer_variations_client_;
};
}  // namespace weblayer

#endif  // WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_