Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1642)

Unified Diff: chrome/browser/chromeos/gdata/gdata_operation_registry.h

Issue 10837338: Remove "GData" prefix from non-GData specific classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_operation_registry.h
diff --git a/chrome/browser/chromeos/gdata/gdata_operation_registry.h b/chrome/browser/chromeos/gdata/gdata_operation_registry.h
deleted file mode 100644
index 7e3424563ebffc85ea833eee2f00004f09d5d82a..0000000000000000000000000000000000000000
--- a/chrome/browser/chromeos/gdata/gdata_operation_registry.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// 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 CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_
-#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "base/id_map.h"
-#include "base/observer_list.h"
-#include "base/time.h"
-
-namespace gdata {
-
-// This class tracks all the in-flight GData operation objects and manage their
-// lifetime.
-class GDataOperationRegistry {
- public:
- GDataOperationRegistry();
- ~GDataOperationRegistry();
-
- // Unique ID to identify each operation.
- typedef int32 OperationID;
-
- // Enumeration type for indicating the direction of the operation.
- enum OperationType {
- OPERATION_UPLOAD,
- OPERATION_DOWNLOAD,
- OPERATION_OTHER,
- };
-
- enum OperationTransferState {
- OPERATION_NOT_STARTED,
- OPERATION_STARTED,
- OPERATION_IN_PROGRESS,
- OPERATION_COMPLETED,
- OPERATION_FAILED,
- OPERATION_SUSPENDED,
- };
-
- // Returns string representations of the operation type and state, which are
- // exposed to the private extension API as in:
- // operation.chrome/common/extensions/api/file_browser_private.json
- static std::string OperationTypeToString(OperationType type);
- static std::string OperationTransferStateToString(
- OperationTransferState state);
-
- // Structure that packs progress information of each operation.
- struct ProgressStatus {
- ProgressStatus(OperationType type, const FilePath& file_path);
- // For debugging
- std::string DebugString() const;
-
- OperationID operation_id;
-
- // Type of the operation: upload/download.
- OperationType operation_type;
- // GData path of the file dealt with the current operation.
- FilePath file_path;
- // Current state of the transfer;
- OperationTransferState transfer_state;
- // The time when the operation is initiated.
- base::Time start_time;
- // Current fraction of progress of the operation.
- int64 progress_current;
- // Expected total number of bytes to be transferred in the operation.
- // -1 if no expectation is available (yet).
- int64 progress_total;
- };
- typedef std::vector<ProgressStatus> ProgressStatusList;
-
- // Observer interface for listening changes in the active set of operations.
- class Observer {
- public:
- // Called when a GData operation started, made some progress, or finished.
- virtual void OnProgressUpdate(const ProgressStatusList& list) = 0;
- // Called when GData authentication failed.
- virtual void OnAuthenticationFailed() {}
- protected:
- virtual ~Observer() {}
- };
-
- // Base class for operations that this registry class can maintain.
- // NotifyStart() passes the ownership of the Operation object to the registry.
- // In particular, calling NotifyFinish() causes the registry to delete the
- // Operation object itself.
- class Operation {
- public:
- explicit Operation(GDataOperationRegistry* registry);
- Operation(GDataOperationRegistry* registry,
- OperationType type,
- const FilePath& file_path);
- virtual ~Operation();
-
- // Cancels the ongoing operation. NotifyFinish() is called and the Operation
- // object is deleted once the cancellation is done in DoCancel().
- void Cancel();
-
- // Retrieves the current progress status of the operation.
- const ProgressStatus& progress_status() const { return progress_status_; }
-
- protected:
- // Notifies the registry about current status.
- void NotifyStart();
- void NotifyProgress(int64 current, int64 total);
- void NotifyFinish(OperationTransferState status);
- // Notifies suspend/resume, used for chunked upload operations.
- // The initial upload operation should issue "start" "progress"* "suspend".
- // The subsequent operations will call "resume" "progress"* "suspend",
- // and the last one will do "resume" "progress"* "finish".
- // In other words, "suspend" is similar to "finish" except it lasts to live
- // until the next "resume" comes. "Resume" is similar to "start", except
- // that it removes the existing "suspend" operation.
- void NotifySuspend();
- void NotifyResume();
- // Notifies that authentication has failed.
- void NotifyAuthFailed();
-
- private:
- // Does the cancellation.
- virtual void DoCancel() = 0;
-
- GDataOperationRegistry* const registry_;
- ProgressStatus progress_status_;
- };
-
- // Cancels all in-flight operations.
- void CancelAll();
-
- // Cancels ongoing operation for a given virtual |file_path|. Returns true if
- // the operation was found and canceled.
- bool CancelForFilePath(const FilePath& file_path);
-
- // Obtains the list of currently active operations.
- ProgressStatusList GetProgressStatusList();
-
- // Sets an observer. The registry do NOT own observers; before destruction
- // they need to be removed from the registry.
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
-
- // Disables the notification suppression for testing purpose.
- void DisableNotificationFrequencyControlForTest();
-
- private:
- // Handlers for notifications from Operations.
- friend class Operation;
- // Notifies that an operation has started. This method passes the ownership of
- // the operation to the registry. A fresh operation ID is returned to *id.
- void OnOperationStart(Operation* operation, OperationID* id);
- void OnOperationProgress(OperationID operation);
- void OnOperationFinish(OperationID operation);
- void OnOperationSuspend(OperationID operation);
- void OnOperationResume(Operation* operation, ProgressStatus* new_status);
- void OnOperationAuthFailed();
-
- bool IsFileTransferOperation(const Operation* operation) const;
-
- // Controls the frequency of notifications, not to flood the listeners with
- // too many events.
- bool ShouldNotifyStatusNow(const ProgressStatusList& list);
- // Sends notifications to the observers after checking that the frequency is
- // not too high by ShouldNotifyStatusNow.
- void NotifyStatusToObservers();
-
- typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap;
- OperationIDMap in_flight_operations_;
- ObserverList<Observer> observer_list_;
- base::Time last_notification_;
- bool do_notification_frequency_control_;
-
- DISALLOW_COPY_AND_ASSIGN(GDataOperationRegistry);
-};
-
-} // namespace gdata
-
-#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698