gdata: Add comments about the threading model of GDataCache

Along the way, make |cache_paths_| const to make it clear that
they won't change.

BUG=131756
TEST=no change in behaviors


Review URL: https://chromiumcodereview.appspot.com/10537161

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142082 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/gdata/gdata_cache.cc b/chrome/browser/chromeos/gdata/gdata_cache.cc
index 13e81a8..23be23ed8 100644
--- a/chrome/browser/chromeos/gdata/gdata_cache.cc
+++ b/chrome/browser/chromeos/gdata/gdata_cache.cc
@@ -56,6 +56,21 @@
   return "unknown subdir";
 }
 
+// Returns file paths for all the cache sub directories under
+// |cache_root_path|.
+std::vector<FilePath> GetCachePaths(const FilePath& cache_root_path) {
+  std::vector<FilePath> cache_paths;
+  // The order should match GDataCache::CacheSubDirectoryType enum.
+  cache_paths.push_back(cache_root_path.Append(kGDataCacheMetaDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCachePinnedDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCacheOutgoingDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCachePersistentDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDownloadsDir));
+  cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDocumentsDir));
+  return cache_paths;
+}
+
 }  // namespace
 
 const char GDataCache::kMountedArchiveFileExtension[] = "mounted";
@@ -80,16 +95,9 @@
     base::SequencedWorkerPool* pool,
     const base::SequencedWorkerPool::SequenceToken& sequence_token)
     : cache_root_path_(cache_root_path),
+      cache_paths_(GetCachePaths(cache_root_path_)),
       pool_(pool),
       sequence_token_(sequence_token) {
-  // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCacheMetaDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCachePinnedDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCacheOutgoingDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCachePersistentDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDownloadsDir));
-  cache_paths_.push_back(cache_root_path_.Append(kGDataCacheTmpDocumentsDir));
 }
 
 GDataCache::~GDataCache() {
diff --git a/chrome/browser/chromeos/gdata/gdata_cache.h b/chrome/browser/chromeos/gdata/gdata_cache.h
index cde682a..63f37678 100644
--- a/chrome/browser/chromeos/gdata/gdata_cache.h
+++ b/chrome/browser/chromeos/gdata/gdata_cache.h
@@ -17,10 +17,16 @@
 
 namespace gdata {
 
+// GDataCache is used to maintain cache states of GDataFileSystem.
+//
+// All non-static public member functions, unless mentioned otherwise (see
+// GetCacheFilePath() for example), should be called from the sequenced
+// worker pool with the sequence token set by CreateGDataCache(). This
+// threading model is enforced by AssertOnSequencedWorkerPool().
 class GDataCache {
  public:
   // Enum defining GCache subdirectory location.
-  // This indexes into |GDataFileSystem::cache_paths_| vector.
+  // This indexes into |GDataCache::cache_paths_| vector.
   enum CacheSubDirectoryType {
     CACHE_TYPE_META = 0,       // Downloaded feeds.
     CACHE_TYPE_PINNED,         // Symlinks to files in persistent dir that are
@@ -122,9 +128,13 @@
 
   // Returns the sub-directory under gdata cache directory for the given sub
   // directory type. Example:  <user_profile_dir>/GCache/v1/tmp
+  //
+  // Can be called on any thread.
   FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
 
   // Returns absolute path of the file if it were cached or to be cached.
+  //
+  // Can be called on any thread.
   FilePath GetCacheFilePath(const std::string& resource_id,
                             const std::string& md5,
                             CacheSubDirectoryType sub_dir_type,
@@ -132,6 +142,8 @@
 
   // Returns true if the given path is under gdata cache directory, i.e.
   // <user_profile_dir>/GCache/v1
+  //
+  // Can be called on any thread.
   bool IsUnderGDataCacheDirectory(const FilePath& path) const;
 
   // TODO(hashimoto): Remove this method when crbug.com/131756 is fixed.
@@ -192,7 +204,7 @@
   const FilePath cache_root_path_;
   // Paths for all subdirectories of GCache, one for each
   // GDataCache::CacheSubDirectoryType enum.
-  std::vector<FilePath> cache_paths_;
+  const std::vector<FilePath> cache_paths_;
   base::SequencedWorkerPool* pool_;
   const base::SequencedWorkerPool::SequenceToken sequence_token_;