summaryrefslogtreecommitdiffstats
path: root/content/browser/geolocation/arbitrator_dependency_factory.h
blob: 8013e1b506c7ff9b31f47c5fa76c025ff5adbd07 (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
// Copyright (c) 2012 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 CONTENT_BROWSER_GEOLOCATION_ARBITRATOR_DEPENDENCY_FACTORY_H_
#define CONTENT_BROWSER_GEOLOCATION_ARBITRATOR_DEPENDENCY_FACTORY_H_
#pragma once

#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "content/common/content_export.h"

class GURL;
class LocationProviderBase;

namespace base {
class Time;
}

namespace content {
class AccessTokenStore;
}

namespace net {
class URLRequestContextGetter;
}

// Allows injection of factory methods for creating the location providers.
// RefCounted for simplicity of writing tests.
class CONTENT_EXPORT GeolocationArbitratorDependencyFactory
    : public base::RefCounted<GeolocationArbitratorDependencyFactory> {
 public:
  // Defines a function that returns the current time.
  typedef base::Time (*GetTimeNow)();

  virtual GetTimeNow GetTimeFunction() = 0;
  virtual content::AccessTokenStore* NewAccessTokenStore() = 0;
  virtual LocationProviderBase* NewNetworkLocationProvider(
      content::AccessTokenStore* access_token_store,
      net::URLRequestContextGetter* context,
      const GURL& url,
      const string16& access_token) = 0;
  virtual LocationProviderBase* NewSystemLocationProvider() = 0;

 protected:
  friend class base::RefCounted<GeolocationArbitratorDependencyFactory>;
  virtual ~GeolocationArbitratorDependencyFactory();
};

// The default dependency factory, exposed so that it is possible
// to override only certain parts (e.g. the location providers).
class CONTENT_EXPORT DefaultGeolocationArbitratorDependencyFactory
    : public GeolocationArbitratorDependencyFactory {
 public:
  // GeolocationArbitratorDependencyFactory
  virtual GetTimeNow GetTimeFunction() OVERRIDE;
  virtual content::AccessTokenStore* NewAccessTokenStore() OVERRIDE;
  virtual LocationProviderBase* NewNetworkLocationProvider(
      content::AccessTokenStore* access_token_store,
      net::URLRequestContextGetter* context,
      const GURL& url,
      const string16& access_token) OVERRIDE;
  virtual LocationProviderBase* NewSystemLocationProvider() OVERRIDE;

 protected:
  virtual ~DefaultGeolocationArbitratorDependencyFactory();
};

#endif  // CONTENT_BROWSER_GEOLOCATION_ARBITRATOR_DEPENDENCY_FACTORY_H_