Ejemplo n.º 1
0
  void OnReceivedData()
  {
    REQUIRE_FILE_THREAD();

    std::vector<std::vector<char>*> data;

    // Remove all data from the pending data queue.
    {
      AutoLock lock_scope(this);
      if(!pending_data_.empty()) {
        data = pending_data_;
        pending_data_.clear();
      }
    }

    if(data.empty())
      return;

    // Write all pending data to file.
    std::vector<std::vector<char>*>::iterator it = data.begin();
    for(; it != data.end(); ++it) {
      std::vector<char>* buffer = *it;
      if(file_)
        fwrite(&(*buffer)[0], buffer->size(), 1, file_);
      delete buffer;
    }
    data.clear();
  }
Ejemplo n.º 2
0
  void OnOpen()
  {
    REQUIRE_FILE_THREAD();

    if(file_)
      return;
    
#if defined(OS_WIN)
    TCHAR szFolderPath[MAX_PATH];

    // Save the file in the user's "My Documents" folder.
    if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, 
                                 NULL, 0, szFolderPath))) {
      std::wstring fileNameStr = filename_;
      LPWSTR name = PathFindFileName(fileNameStr.c_str());
      LPWSTR ext = PathFindExtension(fileNameStr.c_str());
      int ct = 0;
      std::wstringstream ss;

      if(ext) {
        name[ext-name] = 0;
        ext++;
      }

      // Make sure the file name is unique.
      do {
        if(ct > 0)
          ss.str(L"");
        ss << szFolderPath << L"\\" << name;
        if(ct > 0)
          ss << L" (" << ct << L")";
        if(ext)
          ss << L"." << ext;
        ct++;
      } while(PathFileExists(ss.str().c_str()));

      {
        AutoLock lock_scope(this);
        filename_ = ss.str();
      }

      file_ = _wfopen(ss.str().c_str(), L"wb");
      ASSERT(file_ != NULL);
    }
#else
    // TODO(port): Implement this.
    ASSERT(false); // Not implemented
#endif
  }
Ejemplo n.º 3
0
  void OnComplete()
  {
    REQUIRE_FILE_THREAD();

    if(!file_)
      return;

    // Make sure any pending data is written.
    OnReceivedData();

    fclose(file_);
    file_ = NULL;

    // Notify the listener that the download completed.
    listener_->NotifyDownloadComplete(filename_);
  }
Ejemplo n.º 4
0
  void OnComplete() {
    REQUIRE_FILE_THREAD();

    if (!file_)
      return;

    // Make sure any pending data is written.
    OnReceivedData();

    fclose(file_);
    file_ = NULL;

    // Notify the listener that the download completed.
    CefPostTask(TID_UI,
        NewCefRunnableMethod(this, &ClientDownloadHandler::SendComplete));
  }
Ejemplo n.º 5
0
  void OnOpen() {
    REQUIRE_FILE_THREAD();

    if (file_)
      return;

#if defined(OS_WIN)
      std::wstring fileNameStr = filename_;

      file_ = _wfopen(fileNameStr.c_str(), L"wb");
      ASSERT(file_ != NULL);
#else
    // TODO(port): Implement this.
    ASSERT(false);  // Not implemented
#endif
  }