summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/pack_extension_job.h
blob: ec00f21c2a9f665ba1ab53c1f3ac02853ccc64af (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
// Copyright (c) 2009 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 <string>

#include "base/file_path.h"
#include "base/ref_counted.h"

class MessageLoop;

// Manages packing an extension on the file thread and reporting the result
// back to the UI.
class PackExtensionJob : public base::RefCounted<PackExtensionJob> {
 public:

  // Interface for people who want to use PackExtensionJob to implement.
  class Client {
   public:
    virtual void OnPackSuccess(const FilePath& crx_file,
                               const FilePath& key_file) = 0;
    virtual void OnPackFailure(const std::wstring& message) = 0;
  };

  PackExtensionJob(Client* client,
                   const FilePath& root_directory,
                   const FilePath& key_file,
                   MessageLoop* file_loop);

  // The client should call this when it is destroyed to prevent
  // PackExtensionJob from attempting to access it.
  void ClearClient();

 private:
  void RunOnFileThread();
  void ReportSuccessOnUIThread();
  void ReportFailureOnUIThread(const std::string& error);

  MessageLoop* ui_loop_;
  MessageLoop* file_loop_;
  Client* client_;
  FilePath root_directory_;
  FilePath key_file_;
  FilePath crx_file_out_;
  FilePath key_file_out_;

  DISALLOW_COPY_AND_ASSIGN(PackExtensionJob);
};