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_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_INTERFACE_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_INTERFACE_H_
7#pragma once
8
9#include <vector>
10
11#include "base/memory/linked_ptr.h"
12#include "chrome/common/extensions/extension.h"
13
14class FilePath;
15class Version;
16
17// This class is an abstract class for implementing external extensions
18// providers.
19class ExternalExtensionProviderInterface {
20 public:
21  // ExternalExtensionProvider uses this interface to communicate back to the
22  // caller what extensions are registered, and which |id|, |version| and |path|
23  // they have. See also VisitRegisteredExtension below. Ownership of |version|
24  // is not transferred to the visitor.  Callers of the methods below must
25  // ensure that |id| is a valid extension id (use Extension::IdIsValid(id)).
26  class VisitorInterface {
27   public:
28    virtual void OnExternalExtensionFileFound(
29        const std::string& id,
30        const Version* version,
31        const FilePath& path,
32        Extension::Location location) = 0;
33
34    virtual void OnExternalExtensionUpdateUrlFound(
35        const std::string& id,
36        const GURL& update_url,
37        Extension::Location location) = 0;
38
39     // Called after all the external extensions have been reported through
40     // the above two methods.
41    virtual void OnExternalProviderReady() = 0;
42
43   protected:
44    virtual ~VisitorInterface() {}
45  };
46
47  virtual ~ExternalExtensionProviderInterface() {}
48
49  // The visitor (ExtensionsService) calls this function before it goes away.
50  virtual void ServiceShutdown() = 0;
51
52  // Enumerate registered extensions, calling
53  // OnExternalExtension(File|UpdateUrl)Found on the |visitor| object for each
54  // registered extension found.
55  virtual void VisitRegisteredExtension() const = 0;
56
57  // Test if this provider has an extension with id |id| registered.
58  virtual bool HasExtension(const std::string& id) const = 0;
59
60  // Gets details of an extension by its id.  Output params will be set only
61  // if they are not NULL.  If an output parameter is not specified by the
62  // provider type, it will not be changed.
63  // This function is no longer used outside unit tests.
64  virtual bool GetExtensionDetails(const std::string& id,
65                                   Extension::Location* location,
66                                   scoped_ptr<Version>* version) const = 0;
67
68  // Determines if this provider had loaded the list of external extensions
69  // from its source.
70  virtual bool IsReady() = 0;
71};
72
73typedef std::vector<linked_ptr<ExternalExtensionProviderInterface> >
74    ProviderCollection;
75
76#endif  // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_INTERFACE_H_
77