<commit_before>// Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
#pragma once

#include "content/browser/utility_process_host.h"
#include "content/common/url_fetcher.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"

class UtilityProcessHost;
class SkBitmap;

namespace base {
class DictionaryValue;
class ListValue;
}

// This is a class to help dealing with webstore-provided data. It manages
// sending work to the utility process for parsing manifests and
// fetching/decoding icon data. Clients must implement the
// WebstoreInstallHelper::Delegate interface to receive the parsed data.
class WebstoreInstallHelper : public UtilityProcessHost::Client,
                              public URLFetcher::Delegate {
 public:
  class Delegate {
   public:
    enum InstallHelperResultCode {
      UNKNOWN_ERROR,
      ICON_ERROR,
      MANIFEST_ERROR
    };

    // Called when we've successfully parsed the manifest and decoded the icon
    // in the utility process. Ownership of parsed_manifest is transferred.
    virtual void OnWebstoreParseSuccess(
        const SkBitmap& icon,
        base::DictionaryValue* parsed_manifest) = 0;

    // Called to indicate a parse failure. The |result_code| parameter should
    // indicate whether the problem was with the manifest or icon.
    virtual void OnWebstoreParseFailure(
        InstallHelperResultCode result_code,
        const std::string& error_message) = 0;
  };

  // Only one of |icon_data| (based64-encoded icon data) or |icon_url| can be
  // specified, but it is legal for both to be empty.
  WebstoreInstallHelper(Delegate* delegate,
                        const std::string& manifest,
                        const std::string& icon_data,
                        const GURL& icon_url,
                        net::URLRequestContextGetter* context_getter);
  void Start();

 private:
  ~WebstoreInstallHelper();

  void StartWorkOnIOThread();
  void StartFetchedImageDecode();
  void ReportResultsIfComplete();
  void ReportResultFromUIThread();

  // Implementing the URLFetcher::Delegate interface.
  virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;

  // Implementing pieces of the UtilityProcessHost::Client interface.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  // Message handlers.
  void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
  void OnDecodeImageFailed();
  void OnJSONParseSucceeded(const base::ListValue& wrapper);
  void OnJSONParseFailed(const std::string& error_message);

  // The client who we'll report results back to.
  Delegate* delegate_;
<commit_msg>Destructor needs to be virtual.<commit_after>// Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
#pragma once

#include "content/browser/utility_process_host.h"
#include "content/common/url_fetcher.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"

class UtilityProcessHost;
class SkBitmap;

namespace base {
class DictionaryValue;
class ListValue;
}

// This is a class to help dealing with webstore-provided data. It manages
// sending work to the utility process for parsing manifests and
// fetching/decoding icon data. Clients must implement the
// WebstoreInstallHelper::Delegate interface to receive the parsed data.
class WebstoreInstallHelper : public UtilityProcessHost::Client,
                              public URLFetcher::Delegate {
 public:
  class Delegate {
   public:
    enum InstallHelperResultCode {
      UNKNOWN_ERROR,
      ICON_ERROR,
      MANIFEST_ERROR
    };

    // Called when we've successfully parsed the manifest and decoded the icon
    // in the utility process. Ownership of parsed_manifest is transferred.
    virtual void OnWebstoreParseSuccess(
        const SkBitmap& icon,
        base::DictionaryValue* parsed_manifest) = 0;

    // Called to indicate a parse failure. The |result_code| parameter should
    // indicate whether the problem was with the manifest or icon.
    virtual void OnWebstoreParseFailure(
        InstallHelperResultCode result_code,
        const std::string& error_message) = 0;
  };

  // Only one of |icon_data| (based64-encoded icon data) or |icon_url| can be
  // specified, but it is legal for both to be empty.
  WebstoreInstallHelper(Delegate* delegate,
                        const std::string& manifest,
                        const std::string& icon_data,
                        const GURL& icon_url,
                        net::URLRequestContextGetter* context_getter);
  void Start();

 private:
  virtual ~WebstoreInstallHelper();

  void StartWorkOnIOThread();
  void StartFetchedImageDecode();
  void ReportResultsIfComplete();
  void ReportResultFromUIThread();

  // Implementing the URLFetcher::Delegate interface.
  virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;

  // Implementing pieces of the UtilityProcessHost::Client interface.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  // Message handlers.
  void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
  void OnDecodeImageFailed();
  void OnJSONParseSucceeded(const base::ListValue& wrapper);
  void OnJSONParseFailed(const std::string& error_message);

  // The client who we'll report results back to.
  Delegate* delegate_;

{'fraction_non_alphanumeric': 0.07374784110535405, 'fraction_numerical': 0.002763385146804836, 'mean_word_length': 3.643945469125902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6433990', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1561, 'n_words': 517}